Re: php 4.3.0-dev and MySQL 4.0.4-beta (problems with insert)
| From: | 1LT John W. Holmes | Date: | Wed, 23 Oct 2002 18:17:52 +0000 |
| Subject: | Re: php 4.3.0-dev and MySQL 4.0.4-beta (problems with insert) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121144@lists.php.net to get a copy of this message | ||
> I just upgraded from MySQL 3 to MySQL 4. I also upgraded from the
> latest php 4.2 to php 4.3.0-dev.
>
> When I try to insert something into a database that contains a ', I get
> errors:
> You have an error in your SQL syntax. Check the manual that corresponds
> to your MySQL server version for the right syntax to use near
> 't','10-23-2002 12:11:23','20021023121123')' at line 1
>
> Here's the code that worked with MySQL 3:
> $sql = mysql_query("INSERT INTO news (title,content,date,timestamp)
>
> VALUES('$_POST[title]','$_POST[content]','$date','$ts')");
>
> I've tried addslashes(), but it doesn't help any.
>
> The text I entered in "title" was "don't". I realize this is a
> problem
> with MySQL, but I thought I'd ask here first, this list isn't as mean as
> the mysql list. I know it's a problem with mysql because the same thing
> happens when I downgrade my versions of PHP (back to php 4.2).
How are you applying addslashes() to $_POST['title'], because that is your
solution.
$_POST['title'] = addslashes($_POST['title']);
Or turn on magic_quotes_gpc in your php.ini
---John Holmes...