473,785 Members | 3,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

escaping characters in php and mysql - help


// This statement below inserting one field works:
// mysql_query("IN SERT 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("IN SERT INTO page (page_url, title) VALUES
( \"$url_inser t . "\", "." \"$title_fie ld "." "\")");

I don't understand how to escape but I got to believe there's an easier
way? Thanks!

Error message
C:\Program Files\Apache Group\Apache2\h tdocs>php -l populate2.php
<br />
<b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
in <b>C:\Program Files\Apache Group\Apache2\h tdocs\populate2 .php</b> on
line <b>56</b><br />
<br />
<b>Parse error</b>: parse error, unexpected T_CONSTANT_ENCA PSED_STRING
in <b>C:\Program Files\Apache Group\Apache2\h tdocs\populate2 .php</b> on
line <b>56</b><br />
Errors parsing populate2.php
Jul 17 '05 #1
1 1978
leegold2 wrote:

// This statement below inserting one field works:
// mysql_query("IN SERT 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("IN SERT INTO page (page_url, title) VALUES
( \"$url_inser t . "\", "." \"$title_fie ld "." "\")");

I don't understand how to escape but I got to believe there's an easier
way? Thanks!


MySQL supports single quotes around column values as well double quotes so
you can instead do it this way:

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

Much tidier and easier to read.

Note that if you're accepting stuff from the browser and inserting it
directly into the database you need to first escape the values. Do a Google
search on sql injection to learn more:
http://www.google.co.nz/search?q=sql+injection

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1988
by: Reply Via Newsgroup Thanks | last post by:
Folks, This questions is directed towards PHP/MySQL folk and relates to escaping hooks, apostraphe's and other characters that can create a security hole when writing to databases/files. I've been reading http://ca2.php.net/manual/en/function.get-magic-quotes-gpc.php and just need to confirm a couple of things: If I have magic_quotes_gpc on, and I use addslashes() - Does this in effect cause me to take security one step forward, and...
4
4420
by: Dave Moore | last post by:
Hi All, Can anybody point me to a FAQ or similar that describes what all this stuff is about please?. I'm interfacing with a MySQL database if that's relavent. I've read a couple of books which refer to stripslahes and 'escaping' but nothing really explains what these terms are and why these are used. Why is 'escaping' (whatever that is) used?. What the hell is a magic quote?. How is it different from a non-magic one?. Regards, Dave
14
4117
by: Ian Rastall | last post by:
Sorry for the double question. I'm having a terrible time figuring out how to escape apostrophes in my mySQL database. Perhaps they have to be escaped in the PHP, using mysql_real_escape_string? This is the code: http://www.gongfamily.net/code.txt The page in question is:
1
5581
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records. I have specified <xsl:output method="html"/> and encoding="iso-8859-1". When I apply the xsl:value-of and set the disable-output-escaping to "yes", the HTML formatting tags are displayed correctly, but the French accented characters are...
4
3232
by: agarwalpiyush | last post by:
Hello, I am going nuts with trying to get the following to work: This is what I intend to do: I have a line in /etc/syslog.conf which I need to delete based on ip-address provided to me in a variable. Forgetting that variable part for now .. this is what i want in the grep command: grep -suob "\*\.\* *...@172.23.62.12"
4
9183
by: Jon | last post by:
Hi, I used XslCompiledTransform with the following Xsl file. The <xsl:text disable-output-escaping="yes"does not work when using XslCompiledTransform to do the trnasform (namely the output contain < not <), while it works when using MSXML2 to do the transform. Does anyone have the same problem and how to make the escape work? Thanks. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
5389
by: Taras_96 | last post by:
Hi everyone, I'm having a bit of trouble understanding the purpose of escaping nulls, and the use of addcslashes. Firstly, the manual states that: "Strictly speaking, MySQL requires only that backslash and the quote character used to quote the string in the query be escaped. This function quotes the other characters to make them easier to read in
7
4118
by: wannymahoots | last post by:
optparse seems to be escaping control characters that I pass as arguments on the command line. Is this a bug? Am I missing something? Can this be prevented, or worked around? This behaviour doesn't occur with non-control characters. For example, if this program (called test.py): from optparse import OptionParser parser = OptionParser() parser.add_option("-d", dest="delimiter", action="store")
23
2471
by: Fred | last post by:
if I use mysql_real_escape_string on all INSERT or UPDATE queries, then would a stored procedure provide any extra protection? the user has to be granted UPDATE and/or INSERT privileges anyway. Also, I've just noticed this from the manual: "mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string". So for every occasion that I call php's mysql_real_escape_string(), that results in traffic over the socket (or...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.