Page 1 of 1
Having trouble UPDATING MySQL...
Posted: Thu Nov 21, 2002 4:37 am
by Jim
Every time I submit a form to the following page (editusers2.php) I get... nothing. No error, no problems. Just no results. Is there something wrong with the code?
Code: Select all
<?
include("config.php");
if($_POSTї'submit']) {
$sql = "update IamJim_users set user_name = '$new_user_name' and password = '$new_password' and user_email = '$new_user_email' where user_name = '$user_name'";
echo $sql;
$query = mysql_query($sql);
if(!$query) {
echo "Edit failed!";
}
}
?>
Thanks for help!
Re: Having trouble UPDATING MySQL...
Posted: Thu Nov 21, 2002 8:16 am
by f1nutter
Maybe your getting no errors, because everything works! Your only printing error messages, not success!
Run the script and then have a look at the db with phpMyAdmin or whatever, to see if its been updated.
Also, try a few changes to your query: (note the use of single and double quotes)
Code: Select all
<?
include("config.php");
if($_POSTї'submit'])
{
$sql = "update IamJim_users "
. "set user_name = '" .$new_user_name. "' "
. "and password = '" .$new_password. "' and "
. "user_email = '" .$new_user_email. "' "
. "where user_name = '" .$user_name. "'";
echo $sql;
$query = mysql_query($sql);
if(!$query)
{
echo "Edit failed!";
}
else
{
echo "Success!";
}
}
?>
Posted: Thu Nov 21, 2002 8:24 am
by f1nutter
Maybe there is something wrong with the code.
Is this the full script? If so where where you getting the variables from? Where does $new_user_name get set? Is it in the POST array? Add this before the query, and the other variables, and see what you get.
Code: Select all
$new_user_name = $_POSTї'new_user_name'];
echo $new_user_name;
Posted: Thu Nov 21, 2002 9:55 am
by BDKR
Another thing that is potentially deceptive about debugging scripts in browsers is that the erros aren't allways displayed by the browser.
So, check the source!
Cheers,
BDKR
Posted: Thu Nov 21, 2002 4:03 pm
by abdul
I don't know "AND" works with MYSQL or not. But, it is always a good practice to write ANSI SQL for any database. Try this code..
Code: Select all
<?
include("config.php");
if($_POSTї'submit']) {
$sql = "update IamJim_users set user_name = '$new_user_name', password = '$new_password', user_email = '$new_user_email' where user_name = '$user_name'";
echo $sql;
$query = mysql_query($sql);
if($query)
{
echo "Table Updated..!";
}
else
{
echo "Edit failed!";
}
}
?>
Also, the best way to debug an SQL statement is to print it on the browser, copy it and run it directly on MYSQL client editor (Right clicking the mouse button will paste it on MySQL client under windows). It will give you a better error message.
All the best.
Posted: Thu Nov 21, 2002 9:27 pm
by mydimension
deffinetly should have seen that. when listing values for a set directive, use the comma, not 'AND'. AND is for conditional use within a WHERE clause and other places that support it.
Posted: Fri Nov 22, 2002 4:56 am
by Jim
Works fine in PhpMyAdmin when I replace variables with actual names.
The script just won't seem to work it for me.
Maybe something is wrong with the values...
Posted: Fri Nov 22, 2002 5:18 am
by f1nutter
f1nutter wrote:
Is this the full script? If so where where you getting the variables from? Where does $new_user_name get set? Is it in the POST array? Add this before the query, and the other variables, and see what you get.
Code: Select all
$new_user_name = $_POSTї'new_user_name'];
echo $new_user_name;
Better still use $_GET so you can see the variables in the address line for debugging, and when it works, go back to POST