Forum Moderators: coopster
i have a versy simple update statement like this:
if (isset($_POST['submit'])) {
$update = mysql_query("update category set name='$_POST[name]' where id=$cat_id") or die(mysql_error());
header("location:index.php?page=categories");
}
this is the structure of the category table:
id int(11) No
name varchar(100) No
user_id int(11) No 0
now this update statement just won't work, it also doesn't give an error :s
but, however, when I just replace id=$cat_id with where user_id=$user_id in the update statement, it works
if (isset($_POST['submit'])) {
$update = mysql_query("update category set name='$_POST[name]' where user_id=$user_id") or die(mysql_error());
header("location:index.php?page=categories");
}
both $cat_id as $user_id are set correctly so that is certainly not the problem.
I've never seen anything like this?
grtz
id is probably a string as you said, because it is passed with as a GET var.
So I tried to convert it to an integer before passing it to the update statement as follows:
$cat_id = intval($_GET['id']);
if (isset($_POST['submit'])) {
$update = mysql_query("update category set name='$_POST[name]' where id=$cat_id") or die(mysql_error());
header("location:index.php?page=categories");
}
but still little succes :)
Our PHP Forum Library [webmasterworld.com] has some very useful Troubleshooting [webmasterworld.com] tips as well.
Predefined variables [php.net]