mysql not updating php form -


i have database content.

i have page displays table of records. can click edit record wish, when click edit redirects new form , populates information form feilds.

when edit form values , click submit supposed update record in database.

i success message when update,but record doesnt update.

form.php:

    <?php             $emp_id= ($_get["id"]);                 $sql =    "select * people                         id='$emp_id' limit 1";               $result = mysql_query($sql);               $row_people = mysql_fetch_array($result);              ?>                <form method="post" action="update.php?id=<?php echo "$emp_id" ?>">               <input type="hidden" name="id" value="<?php echo "$row_people[id]"; ?>">                  <fieldset>                     <legend><b>name</b></legend>                         first name:<input type="text" name="first_name" size="20" value="<?php echo "$row_people[first_name]"; ?>">                         last name:<input type="text" name="last_name" size="40" value="<?php echo "$row_people[last_name]"; ?>">                 </fieldset> 

update.php

<?php $host="localhost"; // host name $username="root"; // mysql username $password=""; // mysql password $db_name="ogs"; // database name $tbl_name="people"; // table name  // connect server , select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db");  $emp_id= ($_get["id"]); $first_name = $_post["first_name"]; $last_name = $_post["last_name"];  // update data in mysql database $sql="update $tbl_name set first_name='$first_name', last_name='$last_name' id='$emp_id' limit 1"; $result=mysql_query($sql);  // if updated. if($result){ echo "successful"; echo "<br>"; }  else { echo "error"; }  ?>  

not sure missing.

if change $first_name in query actual text, updates fine.

so i'm assuming wrong form.php or $_post?

change $row_people[first_name] $row_people['first_name'] in form.php file. same id , last_name field also.

<?php $emp_id= ($_get["id"]); $id = 0; $firstname = ''; $lastname = '';  $sql = "select * people         id='$emp_id' limit 1"; $result = mysql_query($sql); $row_people = mysql_fetch_array($result);  if(!empty($row_people)) {     $id = $row_people['id'];     $firstname = $row_people['first_name'];     $lastname = $row_people['last_name']; } ?>  <form method="post" action="update.php?id=<?php echo "$emp_id" ?>">     <input type="hidden" name="id" value="<?php echo $id; ?>">     <fieldset>         <legend><b>name</b></legend>         first name:<input type="text" name="first_name" size="20" value="<?php echo $firstname; ?>">         last name:<input type="text" name="last_name" size="40" value="<?php echo $lastname; ?>">     </fieldset> </form> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -