...

View Full Version : Wont Insert Into MySQL



the-dream
08-14-2008, 03:30 PM
It's proabably something really simple im missing, but, this code...


if($_POST['remember'] == 'on') {
$ip = $_SERVER['REMOTE_ADDR'];

mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'yes' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
} else {
$ip = $_SERVER['REMOTE_ADDR'];

mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'no' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
}

Only updates 'ip' to "0" and 'remember' to "" ?

Can you see anything?

oesxyl
08-14-2008, 03:47 PM
It's proabably something really simple im missing, but, this code...


if($_POST['remember'] == 'on') {
$ip = $_SERVER['REMOTE_ADDR'];

mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'yes' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
} else {
$ip = $_SERVER['REMOTE_ADDR'];

mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'no' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
}

Only updates 'ip' to "0" and 'remember' to "" ?

Can you see anything?
yes

regards

JohnDubya
08-14-2008, 04:04 PM
First off, why are you using "social_trees." before all your fields? You already specified "UPDATE social_trees" at the beginning, so using that is extraneous information.

Secondly, what types are those two fields (`ip` and `remember`)? If `ip` were an INT field, that would cause an IP address to become 0 (since there are periods in the IP address, which obviously are not integers).

And if `remember` is only ever 'yes' or 'no', it would be much better for you to make the field TINYINT(1) and have 1 = yes and 0 = no. Does that make sense?

the-dream
08-14-2008, 05:05 PM
The field types are VARCHAR(255). I am happy with the way things are currently being done, if anyone knows of a way to fix it please tell me.

JohnDubya
08-14-2008, 06:07 PM
Also, you use "AND" in between the fields you are trying to set when you should be using a comma. It needs to be like this:



mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."', social_trees.remember = 'yes' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'");

Len Whistler
08-14-2008, 07:40 PM
I would get rid of the if else statement. Try something like:




$on_off = $_POST['remember']; // on/off or yes/no or 1/0

$ip = $_SERVER['REMOTE_ADDR'];

mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."'
AND social_trees.remember = "$on_off" WHERE social_trees.username = '".$user."'
AND social_trees.password = '".$pass."'") or die(mysql_error());



------------------



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum