Be a Supporter!

MYSQL UPDATE function

  • 699 Views
  • 3 Replies
New Topic Respond to this Topic
jonno
jonno
  • Member since: Dec. 15, 1999
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
MYSQL UPDATE function 2001-09-23 16:42:34 Reply

ok guys, i figure out what ive dont wrong here.
im constructing a joke database where you can upload jokes, and vote on them and stuff.

heres what i have for chaging the rating of the joke:

$sql = update jokes //this line is creating an error
$sql.= set rating = $answer
$sql.= where name = $name;

$answer and $name are answered on the previos page.

then i call it with this:

$aQResult = mysql_query( $sql, $aDBLink );

i cant figure out what ive done wrong. any help is apreciated. thanks.

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to MYSQL UPDATE function 2001-09-23 17:07:08 Reply

At 9/23/01 04:42 PM, jonno wrote: heres what i have for chaging the rating of the joke:

$sql = update jokes //this line is creating an error
$sql.= set rating = $answer
$sql.= where name = $name;

Parse error? Looks like it from what you've posted, though I can't be sure... Also, why separate this command over several lines?

By the way, you should enclose the variables with single quote marks. Try this:

$sql = "UPDATE jokes SET rating = '$answer' WHERE name = '$name'"; // Note the use of single and double quotes.

You should check (if you haven't already) whether your server is configured to automatically add slashes with post / get data too - otherwise, you could run into all sorts of problems....

I use a function like this:

function CheckGPC($input) {
if (!get_magic_quotes_gpc()) {
$input = addslashes($input);
}
}

Then use it on variables like this:
$something = CheckGPC($something);

Also, you need to be sure that the data you're getting is in the format you want it... if for example, you're wanting to use scores, you'll want to be sure that the data that's received by your form handler is an integer - a string of non-numericals could otherwise ruin your data.

Just a thought.

hwnd
hwnd
  • Member since: Jan. 31, 2001
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to MYSQL UPDATE function 2001-09-24 19:43:38 Reply

If you can't figure out what's wrong with an sql statement.. try logging into mysql and selecting the database you are using.. then run the sql statement from the command line.. mysql should tell you right where the problem is.

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to MYSQL UPDATE function 2001-09-24 19:51:37 Reply

At 9/24/01 07:43 PM, hwnd wrote: If you can't figure out what's wrong with an sql statement.. try logging into mysql and selecting the database you are using.. then run the sql statement from the command line.. mysql should tell you right where the problem is.

That's assuming he has priveledges to do so :-)