[thelist] PHP - Invalid Query

Chris Rosser chris.rosser at codemasters.com
Fri Jun 11 11:02:19 CDT 2004


Rob,

It's tripping up because there's an apostrophe in $message, which MySQL is
interpreting as a single quote (i.e. it thinks the single quote in "I've" is
the end of the data for the field).

You'll need to use addslashes() or similar to escape any single quotes in
$message before you insert it into the database. Try:

$sql = "INSERT INTO newsarchive (newssubject, newsarchivetext) VALUES
('$subject', '" . addslashes($message) . "')";
mysql_query($sql, $link) or die ("Invalid query");

HTH,

Chris
}:)

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org]On Behalf Of Rob Smith
Sent: 11 June 2004 16:33
To: Thelist (E-mail)
Subject: [thelist] PHP - Invalid Query


Hi list,

I'm getting an "invalid query" in the INSERT query below with PHP. Can you
see anything that may cause it to barf:

Original:
$sql = "INSERT INTO newsarchive (newssubject, newsarchivetext) VALUES ('" .
$subject . "', '" . $message . "')";
mysql_query($sql, $link) or die ("Invalid query");

Actual:
INSERT INTO newsarchive (newssubject, newsarchivetext) VALUES ('Just a Quick
Hello', 'Hi Everyone, My name is Rob and I built this Newsletter System.
I've been having some difficulties with it lately and would like for you to
respond to either me at my at addres.com  if you received this newsletter.
Thank you so much, Rob p.s. See you later!
--------------------------------------------------------- Please reply to
this message if you have questions. If you would like to unsubscribe from
this mailing list click this link:
http://www.mysite.com/unsubscribe.php?nid=1.')

It's PHP and MySQL.

Thanks!

Rob Smith
-- 
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
**********************************************************************



More information about the thelist mailing list