Forum Moderators: coopster

Message Too Old, No Replies

help with mysql query

         

php4life

5:18 pm on Aug 12, 2009 (gmt 0)

10+ Year Member



Hi, i am familaiar with using the sprinf function, however im using a script that i didnt right and i've tried encorparting the mysql_real_escape_string with this and i cant manage it. could anyone tell me how, I've never written SQL statement like this with the "' $title . '" etc

here is the code,

// -- Query to update db => I had to clean this query up quite a bit, no need to assign it to a variable
mysql_query("UPDATE ads SET
title = '" . $title . "',
category = '" . $category . "',
location = '" . $location . "',
body = '" . $body . "',
contact = '" . $contact . "',
email = '" . $email . "',
telephone = '" . $telephone . "',
end = '" . $end . "',
date ='" . $date . "',
author ='" . $author . "' WHERE id = " . $id) or die("Not connecting");

// -- Give a success message => Why use a die() for this? A simple echo will do just fine
die(", <p>Your post has been edited</p><a href='index.php'> Home page</a>");
} else {
echo "<p>Please complete all fields</p>";
}

}

eelixduppy

12:21 am on Aug 13, 2009 (gmt 0)



Try adding some error reporting to the query here:

mysql_query("UPDATE ads SET
title = '" . $title . "',
category = '" . $category . "',
location = '" . $location . "',
body = '" . $body . "',
contact = '" . $contact . "',
email = '" . $email . "',
telephone = '" . $telephone . "',
end = '" . $end . "',
date ='" . $date . "',
author ='" . $author . "' WHERE id = " . $id) or die(mysql_error());

Let me know if you get any mysql error from this now.

BungeeJumper

5:02 am on Aug 13, 2009 (gmt 0)

10+ Year Member



On my server I have to enclose table column names in, well those little thing-a-ma-jigs that look like apostrophes but slant and are smaller :-)

like this

mysql_query("UPDATE ads SET
`title` = '" . $title . "',
`category` = '" . $category . "',
`location` = '" . $location . "',
`body` = '" . $body . "',
`contact` etc etc