You are here: Re: [PHP] PHP MySQL insert « PHP « IT news, forums, messages
Re: [PHP] PHP MySQL insert

Posted by Jordan Miller on 10/19/06 11:24

besides just escaping your strings, i think you are having a quoting
error:
http://www.php.net/manual/en/language.types.string.php

Commas should not have to be escaped, and indeed the
mysql_real_escape_string() function will not escape commas. After
escaping your input data with this function, I would make the $query
text a bit more technically correct:
Change this:
$query = "insert into testtable6 (indx, col1, col2) values (NULL,
'$data1', '$data2')";
to this:
$query = "insert into testtable6 (indx, col1, col2) values (NULL, '".
$data1."', '".$data2."')";
echo $query."<br>\n";

to ensure proper handling of all data in the sql commands.
If you echo your $query before the insert, what do you get? This is
always a good practice when you're having trouble.

Jordan




On Aug 18, 2005, at 12:05 PM, Chris wrote:

> You need to escape the data, so....
>
> $data1 = mysql_real_escape_string($data1,$rLink);
> $data2 = mysql_real_escape_string($data2,$rLink);
>
>
> Jon wrote:
>
>
>> Please help with an insert problem.
>>
>> Sometimes $data1 could have a comma and that messes up the
>> insert. how do I
>> get around that?
>>
>> $query = "insert into testtable6 (indx, col1, col2) values (NULL,
>> '$data1',
>> '$data2')";
>> mysql_db_query("testdb", $query);
>>
>>
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация