mysql - PHP: Record is not updating in SQL -


my problem in updating sql record. fetches sql data form correctly (for editing) when press save edits button returns following erro inside input field:

notice: undefined variable: row in c:\xampp\htdocs\edit.php on line 46
please can tell me how fix it

<html> <body> <?php $servername = "localhost"; $username = "root"; $password = "zz224466"; $database = "zain"; $conn = mysqli_connect($servername,$username,$password,$database); if($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }   if(isset($_get['edit'])) {     $id = $_get["edit"];  //get id of sql table other php page.     echo $id; //it gives true result. means $_get method above gets id of sql table correctly       $res = mysqli_query($conn, "select * product product_id=$id");        if ($res == false) {         die("error");      }     $row = mysqli_fetch_array($res);// getting row sql of specific id above selected above         if (isset($_post['edit'])) {  ///checking if edit button has been pressed         $product_category = $_post['product_category'];         $product_id = $id;  //// sql query         $sql_category = "update product set product_category='$product_category' product_id=$id";         if (mysqli_query($conn, $sql_category)) {          }      } }     ?>  ////////////////////html form///////////////////////// <form method="post" action ="edit.php" id="contact-form">       <input type="text" name="product_category" placeholder="product_category" value="<?php echo $row['product_category'];//it prints sql record in input field updated , prints correctly. when press edit button gives above mentioned error ?>"/>       <div class="btn-group" role="group">         <input type="submit" class="btn btn-default" name="edit" value="save edits" style="margin-top: 15px; margin-right: 15px; border-radius: 4px;">      </div> </form> </body> </html> 

kindly tell me how fix it

try this. because, when pressing submit button. it's going edit.php post value , no get parameters (after pressing edit submit button. so, browser unable find $id resulting it, no $row values.)

<input type="text" name="product_category" placeholder="product_category" value="<?php if(isset($row['product_category'])) { echo $row['product_category'];}?>"/> 

for example, https:www.example.com/edit.php?edit=1

after pressing submit button, url changes

https:www.example.com/edit.php 

so, no edit=1

updated code

change <form> to

<form method="post" action ="edit.php?edit=<?echo $_get['edit'];?>" id="contact-form"> 

additional did before.

full updated code (see lines have written change here)

<html> <body> <?php $servername = "localhost"; $username = "root"; $password = "zz224466"; $database = "zain"; $conn = mysqli_connect($servername,$username,$password,$database); if($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }  if(isset($_get['edit'])) {     $id = $_get["edit"];       echo $id;      $res = mysqli_query($conn, "select * product product_id=$id");     if ($res == false) {         die("error");      }     $row = mysqli_fetch_array($res);     if (isset($_post['edit'])) {           $product_category = $_post['product_category'];         $product_id = $_get['edit']; // change here          // changes here          $sql_category = "update product set product_category='$product_category' product_id=$product_id";         if (mysqli_query($conn, $sql_category)) {          }     } }?>     // changes here in form tag      <form method="post" action ="edit.php?edit=<?echo $_get['edit'];?>" id="contact-form">            <input type="text" name="product_category" placeholder="product_category" value="<?php if(isset($row['product_category'])) { echo $row['product_category']; }?>"/>           <div class="btn-group" role="group">               <input type="submit" class="btn btn-default" name="edit" value="save edits" style="margin-top: 15px; margin-right: 15px; border-radius: 4px;">           </div>     </form> </body> </html> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -