[SOLVED] UPDATE Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

[SOLVED] UPDATE Query

Post 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?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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'
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

Thanks, that worked :D
Post Reply