Jump to content


Photo

MySQL Query Problem


  • Please log in to reply
2 replies to this topic

#1 nathanb

nathanb
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 March 2006 - 01:07 AM

Hi, I am editing a script and sometimes this query works and sometimes it does not. Here is the particular code that is (sometimes) malfunctioning:
if (($_POST['description']!='DEBUG')||(!in_array('DEBUG', $_POST))) $query1 = mysql_query("INSERT INTO countdowns (`creator`, `creationdate`, `countdowndate`, `type`, `description`, `private`, `timezone`, `special`, `specialinfo`) VALUES ('$creator', '$creationdate', '$countdowndate', '".($tag=='official'?'official':'user')."', '$description', '$private', '$ctimezone', '$special', '$specialinfo')");

In a working case, the variables include something like this:
$creator = '1';
$creationdate = '1141347209';
$countdowndate = '1141362000';
$description = "rarw";
$private = '1';
$timezone = 'GMT-5';
$special = '';
$specialinfo = '';

and it goes through as expected as it always did. Another working case is this:
$creator = '1';
$creationdate = '1141347209';
$countdowndate = '1141362000';
$type = '';
$description = "So and so.. Auction Ends";
$private = '1';
$timezone = 'GMT-5';
$special = 'ebay';
$specialinfo = '4437837371';

But this and others do not work:
$creator = '1';
$creationdate = '1141347209';
$countdowndate = '1141362000';
$description = "Jim's 1st Anniversary";
$private = '1';
$timezone = 'GMT-5';
$special = 'anniversary of marriage';
$specialinfo = '1st|Jim';

The $query1 variable appears to be null, but it shouldn't. mysql_error() says that it is not a valid MySQL Link Resource.. Note that this doesn't happen in the above working cases.

Any ideas? Thanks in advance!

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 03 March 2006 - 01:19 AM

the error was because of an apostrophe in the following string:
$description = "Jim's 1st Anniversary";

Your server doesn't addslashes to post values automatically. one option is to set the php.ini directive magic_quotes_gpc to "on", or use the following script to clean up description
if(!get_magic_quote_gpc())
{
   $_POST['description'] = addslashes($_POST['description']);
}

//produces: Jim\'s 1st Anniversary

the following script will addslashes to all post values (except arrays)
foreach($_POST as $k=>$v)
{
  $_POST[$k] = !get_magic_quote_gpc() ? addslashes($v) : $v;
}

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 nathanb

nathanb
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 March 2006 - 01:24 AM

Ack! I knew it was going to be something simple like that! Thank you!

And, luckily, it looks like the rest of the site is already adapted for the slashes, this was just a minor oversight.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users