Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2009, 12:49 AM
Authorized User
 
Join Date: Feb 2007
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dhillon555
Default You have an error in your SQL syntax;

I am loosing sleep over the following error can anybody help me



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 '\'tom\'' at line 1

Code:

$username = mysql_escape_string($_SESSION['myusername']); 

$query = "SELECT user_info.username, user_info.password, user_info.UserID, user_info.EmailAddress, user_info.Address, user_info.Postcode, user_info.FirstName, user_info.LastName FROM user_info WHERE user_info.username = '$username'"; 

$results = mysql_query(mysql_escape_string($query))
    or die(mysql_error());
    
while ($row = mysql_fetch_array($results)) {
    extract($row);
    
    echo $username;
    echo $password;
    echo $UserID;
    echo $EmailAddress;
    echo $Address;
    echo $Postcode;
    echo $FirstName;
    echo $LastName;
    
    
    
    
}
    



    
?>
 
Old June 5th, 2009, 09:56 AM
Authorized User
 
Join Date: Mar 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default blam


Change this:


$results = mysql_query(mysql_escape_string($query))
to this:


$results = mysql_query($query)
And it should work.


Then read this: http://us.php.net/mysql_escape_string

p.s. Looks like you are using an old version of php? (Your query should have a db resource handle.)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in SQL syntax phantom3008 ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2007 07:00 AM
Example SQL causes syntax error Tom Rigby BOOK: Beginning SQL 1 April 18th, 2007 09:32 AM
SQL syntax error - Chapter 3 cutthroatchemist BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 January 15th, 2007 06:19 PM
SQL Syntax Error I can't figure out Syster Tara Classic ASP Basics 24 December 2nd, 2006 05:09 PM
Syntax error on SQL statement Chris1 Access VBA 1 September 7th, 2004 07:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.