Page 1 of 1

[SOLVED] UPDATE Query

Posted: Wed Aug 11, 2004 12:06 am
by dwfait
Hi. I asked about this some time ago, and i still cannot get it to work.

Here is the code:

Code: Select all

} else if ($action=='cpcadf') {
   if (is_null($suser)) {
   echo "You are not logged in.";
   } else {
   
$user = $_POST["user"];
$pass = $_POST["pass"];
$nname = $_POST["nname"];
$email = $_POST["email"];
       $link = mysql_connect("localhost", "root", "")
        or die("Could not connect");


mysql_select_db("stormst_sspp")
        or exit("Could not select database");
        
$mpass=MD5($pass);
$result=mysql_query("select id,user,pass from sspp WHERE user='$user' and pass='$mpass'");

if (mysql_num_rows($result)==0) {
echo "Error: Incorrect username/password.";
} else {
list($id) = mysql_fetch_row($result);

$query = "UPDATE sspp SET nname='$nname' AND email='$email' WHERE id='$id'";
if(mysql_query($query))
{
   echo "Changes made successfully.";
}
else
{
  echo "Changes could not be carried out.";
}
   
}
mysql_close($link);

}
}
It says Changes made successfully, but the changes arent made. Can anyone help?

Posted: Wed Aug 11, 2004 12:21 am
by hawleyjr
Try putting an echo of your query just before your update statement. Run the query directly in you datase and see if it returns an error. Typically there is an error in your query that you won't be able to see running it through PHP.

Posted: Wed Aug 11, 2004 12:23 am
by hawleyjr
Also, I just noticed...In your update statement you have id wrapped in single quotes. Typically an id is a neumeric therefore it shouldn’t be in quotes.

Posted: Wed Aug 11, 2004 1:55 am
by dwfait
in the echo, all the information is there and correct. Also, no matter what i put as the nickname, it always comes out as 0 in the database.

Posted: Wed Aug 11, 2004 2:05 am
by feyd

Code: Select all

SET nname='$nname' AND email='$email'
sets nname to the boolean returned from "'$nname' AND email='$email'" .... you want:

Code: Select all

SET nname='$nname', email='$email'

Posted: Wed Aug 11, 2004 2:14 am
by dwfait
Thanks, that worked :D