Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '<!doctype html>
- <html>
- <head>
- <title>Table_Process</title>
- <meta charset="UTF-8">
- </head>
- <body>
- <h3>Επεξεργασία Πίνακα Mysql Βάσης με PHP pg1</h3>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "music";
- // Create connection
- $conn =new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- else{
- echo "connection ok . ";
- }
- $sql = "SELECT * FROM compact_discs;";
- $result=$conn->query($sql);
- $sql2= "SELECT artist_id FROM artists;";
- $result2=$conn->query($sql2);
- if ($result->num_rows>0)
- {
- echo "<center><h5> Επέλεξε την αλλαγή που θές [Σε πεδίο(Update) ή σε γραμμή(Delete ή Insert)]. </h5>
- <form action='table_process2_or.php' method='post'><table><tr>
- <th> </th>
- <th> COMPACT DISC ID </th>
- <th> CD TITLE </th>
- <th> LABEL ID </th>
- <th> IN STOCK </th>
- <th> PRICE </th>
- <th> COPYRIGHT </th>
- <th> ARTIST ID </th>
- </tr>";
- // output data of each row
- while ($row = $result->fetch_assoc())
- {
- echo "<tr>
- <td><input type='checkbox' name='del[]' value='delete'>Delete</td>
- <td><input type='text' name='id[]' value='". $row["COMPACT_DISC_ID"]."' readonly></td>
- <td><input type='text' name='cd_title[]' value='". $row["CD_TITLE"]."'></td>
- <td><input type='text' name='label[]' value='". $row["LABEL_ID"]."'></td>
- <td><input type='text' name='stock[]' value='". $row["IN_STOCK"]."' > </td>
- <td><input type='text' name='price[]' value='". $row["PRICE"]."' > </td>
- <td><input type='text' name='copyright[]' value='". $row["COPYRIGHT"]."'></td>
- <td><input list='artist' name='artist[]' value='". $row["ARTIST_ID"]."'>
- <datalist id='artist'>";
- if ($result2->num_rows>0)
- {
- while ($row2 = $result2->fetch_assoc())
- {
- echo "<option value='". $row2["artist_id"]."'>";
- }
- }
- echo " </datalist>
- </td>
- </tr>";
- }
- echo "<tr>
- <td>Insert =></td>
- <td><input type='text' name='cd' ></td>
- <td><input type='text' name='title' ></td>
- <td><input type='text' name='lbl' ></td>
- <td><input type='text' name='rmns' ></td>
- <td><input type='text' name='prc' ></td>
- <td><input type='text' name='copy' ></td>
- <td><input list='artist' name='art' >
- <datalist id='artist'>";
- if ($result2->num_rows>0)
- {
- while ($row2 = $result2->fetch_assoc())
- {
- echo "<option value='". $row2["artist_id"]."'>";
- }
- }
- echo " </datalist>
- </td>
- </tr>
- </table>
- <input type='submit' name='submit' value='ΥΠΟΒΟΛΗ ΑΛΛΑΓΗΣ'>
- </form>
- </center>";
- }
- else
- {
- echo "0 results";
- }
- $conn->close();
- ?>
- </body>
- </html>'
- The code for the 2nd page is:
- '<!doctype html>
- <html>
- <head>
- <title>Table_Process</title>
- <meta charset="UTF-8">
- </head>
- <body>
- <h3>Επεξεργασία Πίνακα Mysql Βάσης με PHP pg2</h3>
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors','On');
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "music";
- // Create connection
- $conn =new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- else{
- echo "connection ok <br>";
- }
- if (isset($_POST["submit"]))
- {
- $i=0;
- //del var
- $del=$_POST["del"];
- $cdtitle=$_POST["cd_title"][$i];
- $label=$_POST["label"][$i];
- $stock=$_POST["stock"][$i];
- $price=$_POST["price"][$i];
- $copyright=$_POST["copyright"][$i];
- $artist=$_POST["artist"][$i];
- $cdid=$_POST["id"][$i];
- $size=count($cdid);
- $size=count($cdtitle);
- $size=count($label);
- $size=count($stock);
- $size=count($price);
- $size=count($copyright);
- $size=count($artist);
- while($i<$size)
- {
- if (isset($del))
- {
- $del=$_POST["del"][$i];
- $dlt1="DELETE FROM compact_discs WHERE compact_disc_id = '".$cdid."';";
- $dlt1 = mysqli_query($conn,$dlt1);
- if($dlt1){echo " rows deleted ";} else { echo " rows not deleted ".var_dump($dlt1);}
- }
- $updt="UPDATE compact_discs SET CD_TITLE='".$cdtitle."', LABEL_ID='".$label."',IN_STOCK='".$stock."',price='".$price."', COPYRIGHT='".$copyright."',ARTIST_ID='".$artist."', WHERE COMPACT_DISC_ID='".$cdid."';";
- $updt = mysqli_query($conn,$updt);
- if($updt){echo " rows updated ";} else {echo " rows not updated ".var_dump($updt);}
- $i++;
- }
- //Insert vars
- $cd=$_POST["cd"];
- $title=$_POST["title"];
- $lbl=$_POST["lbl"];
- $rmns=$_POST["rmns"];
- $prc=$_POST["prc"];
- $copy=$_POST["copy"];
- $art=$_POST["art"];
- if($cd<>0 or $title<>0 or $lbl<>0 or $rmns<>0 or $prc<>0 or $copy<>0 or $art<>0)
- {
- $ins="INSERT INTO compact_discs (COMPACT_DISC_ID, CD_TITLE, LABEL_ID, IN_STOCK, PRICE, COPYRIGHT, ARTIST_ID) VALUES ('".$cd."', '".$title."', '".$lbl."', '".$rmns."', '".$prc."', '".$copy."', '".$art."');";
- $ins = mysqli_query($conn,$ins);
- if($ins){echo " row inserted ";} else {echo " row not inserted ".var_dump($ins);}
- }
- }
- $sql = "SELECT * FROM compact_discs;";
- $result=$conn->query($sql);
- if ($result->num_rows>0)
- {
- echo "<center>
- <form><table><tr>
- <th> COMPACT DISC ID </th>
- <th> CD TITLE </th>
- <th> LABEL ID </th>
- <th> IN STOCK </th>
- <th> PRICE </th>
- <th> COPYRIGHT </th>
- <th> ARTIST ID </th>
- </tr>";
- // output data of each row
- while ($row = $result->fetch_assoc())
- {
- echo "<tr>
- <td><input type='text' value='". $row["COMPACT_DISC_ID"]."' readonly></td>
- <td><input type='text' value='". $row["CD_TITLE"]."' readonly></td>
- <td><input type='text' value='". $row["LABEL_ID"]."' readonly></td>
- <td><input type='text' value='". $row["IN_STOCK"]."' readonly> </td>
- <td><input type='text' value='". $row["PRICE"]."' readonly> </td>
- <td><input type='text' value='". $row["COPYRIGHT"]."' readonly></td>
- <td><input type='text' value='". $row["ARTIST_ID"]."' readonly></td>
- </tr>";
- }
- echo "</table>
- </form>
- </center>";
- }
- else
- {
- echo "0 results";
- }
- mysqli_commit($conn);
- $conn->close();
- ?>
- </body>
- </html>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement