Re: [PHP-DB] Stuck in apostrophe hell

[email protected] (Peter Lind)
Newsgroups php.db
Message-ID <[email protected]>
On 2 August 2010 22:30,  <[email protected]> wrote:
> Before I send the following SQL to MySQL from PHP I print it to screen.
> PHP chokes on it, but I can paste the exact same query from the screen
> directly to MySQL and it works just fine. For example:
>
> Here's the relevant PHP code:
> ======================================
> $sql_insert_registration = sprintf("INSERT INTO
>  Registrations (
>    Class_ID,
>    prid,
>    Registrant,
>    Company,
>    Phone,
>    Email
>  )
> VALUES (
>    $_POST[Class_ID],
>    $_POST[prid],
>    '%s',".
>    parseNull($_POST['Company']).",
>    '$_POST[Phone]',
>    '$_POST[Email]'
> )", mysql_real_escape_string($_POST['Registrant']));
>
> echo "<pre>".$_POST["Registrant"]."</pre>";
> echo "<pre>".mysql_real_escape_string($_POST["Registrant"])."</pre>";
> echo "<pre>".$sql_insert_registration."</pre>";
>
> if (!mysql_query($sql_insert_registration, $con)) {
>  die('Error: ' . mysql_error());
> ....
> ======================================
>
>
> Here's the output:
> =======================
>
> INSERT INTO
>  Registrations (
>    Class_ID,
>    prid,
>    Registrant,
>    Company,
>    Phone,
>    Email
>  )
> VALUES (
>    355,
>    257,
>    'Brian O\'Brien',NULL,
>    '612-456-5678',
>    '[email protected]'
> )
> Error: 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
> 'Brien', 'Class registration confirmation', ' This email ' at line 16
> ==================================================

It's probably nothing but your mysql error does not match your php
output - could you try an updated paste?

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.