bigfuzz Posted March 26, 2012 Share Posted March 26, 2012 I'm having an issue updating a records. The insert and delete functions are working fine. The $submit variable is being passed 'Update' ~ that is working. This is some extremely old code that has migrated to a new server and is no longer working. <?php $id = $_GET["id"]; $delete = $_GET["submit"]; $sortorder = $_POST["sortorder"]; $name = $_POST["name"]; $content = $_POST["content"]; $submit = $_POST["submit"]; require'../include/maindb.php'; if($submit=="Submit") { $sql="INSERT INTO biography (id, sortorder, name, content) VALUES (NULL, '".$sortorder."', '".nl2br(addslashes(trim($name)))."', '".htmlentities(addslashes(trim($content)))."')"; } if ($submit == "Update") { $sql="UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"; } if ($delete=="Delete") { $sql="DELETE FROM biography WHERE id='".$id."'"; } mysql_query($sql); echo(mysql_error()); header('Location: index.php'); ?> Link to comment https://forums.phpfreaks.com/topic/259745-update-record-help/ Share on other sites More sharing options...
dragon_sa Posted March 26, 2012 Share Posted March 26, 2012 How come id and delete are GET variables? shouldnt they be POST echo out the $id somewhere to make sure you are getting what you are expecting and $sql=mysql_query("UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"); Link to comment https://forums.phpfreaks.com/topic/259745-update-record-help/#findComment-1331234 Share on other sites More sharing options...
bigfuzz Posted March 26, 2012 Author Share Posted March 26, 2012 That was the problem!! For the update function I needed to use the POST variable. Thanks - I owe you a beer. Link to comment https://forums.phpfreaks.com/topic/259745-update-record-help/#findComment-1331259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.