Jump to content

[SOLVED] UPDATE query not updating row?


Presto-X

Recommended Posts

Hello guys,

 

I have been working on this page most of the night and my eyes are killing me, can any one see what I'm missing here? Where using the INSERT INTO in works great but when it needs to use UPDATE it does not save the data to the database  ???

 

if(isset($_POST['submit'])){
mysql_select_db($database_startpage, $startpage);
$id = $_POST['id'];
$icon = $_POST['icon'];
$title = $_POST['title'];
$url = $_POST['url'];
$order = $_POST['order'];
$target = $_POST['target'];

if (empty($_POST['id'])){
  $query = "INSERT INTO icons VALUES ('','$icon','$title','$url','$order','$target')";
}else{
  $query = "UPDATE icons SET icon='$icon', title='$title', url='$url', order='$order', target='$target' WHERE id='$id'";
}
mysql_query($query);

echo '<h1>Icon Saved!</h1>
<meta http-equiv="refresh" content="1;url=icons_edit_list.php" />';

}

 

this is the top of my form

<form action="icons_form.php<?PHP if (isset($_GET['id'])){echo '?id='.$_GET['id'];} ?>" method="POST">
<input type="hidden" name="id" value="<?PHP echo $_GET['id']; ?>" />
<input type="hidden" name="submit" value="1" />

Link to comment
https://forums.phpfreaks.com/topic/131166-solved-update-query-not-updating-row/
Share on other sites

try changing "mysql_query($query);" to: "mysql_query($query) or die(mysql_error());" .. should tell you of any errors..

 

This may not be a great concern right now but you leave your script wide open to sql injections (google it for more information) ..

 

Adam

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.