Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help escaping characters in PHP/MYSQL

Status
Not open for further replies.

leegold

Technical User
Mar 19, 2002
39
US
Note: note sure if the MYSQL is a better forum - if so please tell me - I'm really not sure which to post to. Anyway please see ques. below,


// This statement below works:
// mysql_query("INSERT INTO page (page_url) VALUES (\"$url_field\")");

But I wanted to insert into two fields so I was trying all sorts of escaping. See below...there must be an easier way?! I also cite the syntax error - Thanks very much.

mysql_query("INSERT INTO page (page_url, title) VALUES
( \"$url_insert . "\", "." \"$title_field "." "\")");

I don't understand how to escape and I imagine there's an easier way! Thanks!


Error message
C:\Program Files\Apache Group\Apache2\htdocs>php -l populate2.php
<br />
<b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>C:\Program Files\Apache Group\Apache2\htdocs\populate2.php</b> on line <b>56</b><br />
<br />
<b>Parse error</b>: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in <b>C:\Program Files\Apache Group\Apache2\htdocs\populate2.php</b> on line <b>56</b><br />
Errors parsing populate2.php
 
Try this:

[tt]
mysql_query("INSERT INTO page (page_url, title) VALUES ('$url_insert', '$title_field')");
[/tt]

Text values in SQL Statements should be separated with 'single quotes' rather than "double quotes". I'm not sure what you were doing with your SQL syntax! Anyway, the solution above should do the trick for you.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top