php - Peform an update if action selected is edit -


i have link <a href='test.php?action=edit&id=$id'>edit</a>

if user clicks on link update form displayed, him/she update

the $action=="edit";

is action perfomed in case must update, how ever not here in code

if ($action == "edit"){  if ($_server['request_method'] == 'post') {       $first_name = $_post['first_name'];     $last_name = $_post['last_name'];     $email = $_post['email'];      $result=mysql_query("update user set first_name='$first_name',last_name='$last_name',email='$email' id = '$id'");       $sql = mysql_query($result) or die (mysql_error()); } sql=mysql_query("select * user id='$id'");     while ($row=mysql_fetch_array($sql))   {                                                                                                                                                                                                                                                       $id = $row['id']; $first_name = $row['first_name']; $last_name = $row['last_name']; $email = $row['email'];               $result=mysql_query("update user set first_name='$first_name',last_name='$last_name',email='$email' id=$id");               $sql = mysql_query($result) or die (mysql_error());  ho("<form name='edit' method='post' action='?action=edit'>"); echo("<input type='hidden' name='?action=edit'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>name: </td><td align='right'><input type='text'  name='first_name' value='$first_name'></td></tr>"); echo("<tr><td>surname: </td><td align='right'><input type='text' name='last_name' value='$last_name'></td></tr>"); echo("<tr><td>email: </td><td align='right'><input type='text'  name='email' value='$email'></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='submit'></div></td></tr>"); echo("</table>");  } } 

is there way query return value cause seems not workng...

im suspecting line

$result=mysql_query("update user set first_name='$first_name',last_name='$last_name',email='$email' id=$id");                   $sql = mysql_query($result) or die (mysql_error()); 

cause if add the

where id = '$id' 

it ruturns have error in sql syntax; check manual corresponds mysql server version right syntax use near '1' @ line 1

if removed

where id = $id 

it returns "query empty" need ive been working on not working right

instead of this:

$result=mysql_query("update user set first_name='$first_name',last_name='$last_name',email='$email' id = '$id'");  $sql = mysql_query($result) or die (mysql_error()); 

you should this:

 $sql = "update user set first_name='$first_name',last_name='$last_name',email='$email' id = '$id'");   mysql_query($sql) or die (mysql_error()); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -