Trying to 'addslashes()' to a mySQL DB w/ PHP

phaxmohdem

Golden Member
Aug 18, 2004
1,839
0
0
www.avxmedia.com
Hello,

I created a database as a study tool for some classmates of mine, and I just recently realized that I am a moron for not saving the entries in it with "\" slashes before them using the php addslashes(string) command. Now I have errors when running certain SQL statements on the data. I tried to write a script that would:

- Recurse every entry in the database (only around 500 as of now)
- Pull data that needs to be addslashed ans save to a variable
- use UPDATE sql command to resave entry with slashes.

It looks like it should work to me.. however when the script is run, the database does not appear to be updated. The data stored in it does not have slashes after runtime... Here is the code.. any help? (Also note when run, the "$display_block" that is printed on the html page DOES contain slashes as they should appear... they are just not getting updated or something in the DB)
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
put quotes around your string.

mysql_query("UPDATE saqa SET question='" . $addquestion . "', answer='" . $addanswer . "' WHERE id = $addid");


you can test to see if the query itself is the problem by using mysql_error():

mysql_query("UPDATE saqa SET question='" . $addquestion . "', answer='" . $addanswer . "' WHERE id = $addid") or die(mysql_error());

if it errors out it will print the mysql syntax error message. if not, then the query was successfull.