Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <html>
  2. <body>
  3. <?php
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "zz224466";
  7. $database = "zain";
  8. $conn = mysqli_connect($servername,$username,$password,$database);
  9. if($conn->connect_error) {
  10. die("connection failed: " . $conn->connect_error);
  11. }
  12.  
  13.  
  14. if(isset($_GET['edit'])) {
  15. $id = $_GET["edit"]; //Get id of sql table from other php page.
  16. echo $id; //It gives true result. It means that $_GET method above gets id of sql table correctly
  17.  
  18.  
  19. $res = mysqli_query($conn, "SELECT * FROM product where product_id=$id");
  20.  
  21.  
  22.  
  23. if ($res == FALSE) {
  24. die("Error");
  25.  
  26. }
  27. $row = mysqli_fetch_array($res);// Getting row from sql of specific id above selected above
  28.  
  29.  
  30.  
  31.  
  32. if (isset($_POST['Edit'])) { ///Checking if Edit button has been pressed
  33. $product_category = $_POST['product_category'];
  34. $product_id = $id;
  35.  
  36. //// SQL query
  37. $sql_category = "UPDATE product SET product_category='$product_category' WHERE product_id='$product_id'";
  38. if (mysqli_query($conn, $sql_category)) {
  39.  
  40. }
  41.  
  42. }
  43. }
  44. ?>
  45.  
  46. ////////////////////HTML FORM/////////////////////////
  47. <form method="post" action ="edit.php" id="contact-form">
  48.  
  49.  
  50. <input type="text" name="product_category" placeholder="product_category" value="<?php echo $row['product_category'];//It prints sql record in input field which is to be updated and it prints correctly. But when I press edit button it gives above mentioned error ?>"/>
  51.  
  52.  
  53. <div class="btn-group" role="group">
  54. <input type="submit" class="btn btn-default" name="Edit" value="Save Edits" style="margin-top: 15px; margin-right: 15px; border-radius: 4px;">
  55.  
  56. </div>
  57. </form>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement