Page 1 of 2

UPDATING database

Posted: Sat Apr 02, 2005 10:28 am
by anthony88guy
When I try and update the database, nothing is changed to the database.

Posted: Sat Apr 02, 2005 10:47 am
by feyd
check what is being sent to mysql.. hint: echo the query string.

Posted: Sat Apr 02, 2005 11:13 am
by anthony88guy
how do you echo the query?

Posted: Sat Apr 02, 2005 11:20 am
by feyd

Code: Select all

echo &quote;UPDATE users SET pass = '$encryptedpass' WHERE user = '$username'&quote;;

Posted: Sat Apr 02, 2005 12:31 pm
by anthony88guy
ok, i did that and found 2 errors. Now when i use mysql_query with the correct values it doesnt change my armysize. I wanted to change strikeaction to 10,000,000 and it changed it to 0 in the database. I used str_replace(",","",$strikeaction) to get rid of the comma's. Whats wrong now?

Posted: Sat Apr 02, 2005 12:41 pm
by feyd
ensure they don't have any non-numeric characters in them. Echo your query again, in a fixed width display, maybe you have a space stuck in there..

Posted: Sat Apr 02, 2005 2:51 pm
by anthony88guy
what about using trim() wouldn't that do it? I'm have no luck.

Posted: Sat Apr 02, 2005 2:55 pm
by feyd

Code: Select all

$onlyNumbers = preg_replace('#[^\d]#', '', $mixedText);

Posted: Sat Apr 02, 2005 3:24 pm
by anthony88guy
Are you sure that that could do it because, i did type in numbers. What else could prevent it from updating. Also if you type a number over 1 it sets it to 1. If i type 0 it sets it to 0. I think it is a true and false thing going on. But i would like to put numbers in, not true and false values.

Posted: Sat Apr 02, 2005 3:42 pm
by feyd
post an SQL form of your table structure.

Posted: Sat Apr 02, 2005 4:52 pm
by anthony88guy
Is this what you meant?

Posted: Sat Apr 02, 2005 5:19 pm
by feyd
armysize is a string type. Can you post your newest code?

Posted: Sat Apr 02, 2005 5:47 pm
by anthony88guy
edited

Posted: Sat Apr 02, 2005 8:20 pm
by feyd
oh.. I didn't see this before... how silly of me.. 'AND' is the problem. You are supposed to seperate the fields using commas, not logicals. The logical is processed as part of the expression, therefore if $newstrikeaction and $newarmysize are non-zero, strikeaction will get one, otherwise zero.

Posted: Sat Apr 02, 2005 9:11 pm
by anthony88guy
thxs so much. So you use "AND" when you are Selecting, and use comma's when you are updating?