Run Time UPDATE command is not working

[php]

<?php $con=mysql_connect("localhost","root","gana") or die("could not connect"); if ($_POST['Submit'] == "insert") { mysql_select_db("admin",$con); mysql_query("insert into register values('$_POST[name]','$_POST[department]','$_POST[year]','$_POST[percentage]','$_POST[mobile]');"); echo 'Data Inserted Successfully'; } if ($_POST['Submit'] == "update") { mysql_select_db("admin"); mysql_query("update register set '$_POST[department]','$_POST[year]','$_POST[percentage]','$_POST[mobile]' where '$_POST[name]';"); echo 'Data Updated Successfully'; } ?>

[/php]

Here…insert command is working…but run time update command is not working and data base not update the values…please help me asap

its not working because the update query is wrong
[php]

<?php mysql_connect("localhost","root","gana") or die("could not connect"); mysql_select_db("admin"); if($_POST['Submit'] == "insert") { $ins = mysql_query("INSERT INTO register VALUES ('$_POST[name]','$_POST[department]','$_POST[year]','$_POST[percentage]','$_POST[mobile]')") or die(mysql_error()); if($ins) { echo 'Data Inserted Successfully'; } } if($_POST['Submit'] == "update"){ $upd = mysql_query("UPDATE register SET department = '$_POST[department]', year = '$_POST[year]', percentage = '$_POST[percentage]', mobile = '$_POST[mobile]' WHERE name = '$_POST[name]';") or die(mysql_error()); if($upd) { echo 'Data Updated Successfully'; } } ?>

that should work. Unless you’re moving between different databases, you only seen to select it once, which is why i moved it up top and got rid of the 2nd reference. Also added some if statements to make sure that the success messages are accurate. the way you had it, it would show whether it updated or not.

Sponsor our Newsletter | Privacy Policy | Terms of Service