MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2013, 03:54 PM
ianhaney ianhaney is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 91 ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 23 sec
Reputation Power: 11
MySQL help

Hi all

I am sort of new to MySQl

I have installed a script on my website and need help with the following if ok

my wife created a account and used a few capital letters and a space in her username and logged in all ok and the page is where to write status updates and where a share button is, I am getting the following error, it only happens when capital letters and spaces are used

How would I go about fixing it please

Error: 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 's' ORDER BY messages_id DESC' at line 1

Thank you in advance, I can paste any coding or give the website address if need be to look at

Thanks in advance

Ian

Reply With Quote
  #2  
Old January 16th, 2013, 05:08 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 9 h 12 m 42 sec
Reputation Power: 7053
It sounds like a problem with the script you installed. If the script is throwing that sort of error it usually means there is a SQL injection vulnerability in it and you would be advised to not use it.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old January 16th, 2013, 06:13 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by ianhaney
I can paste any coding
paste the query that's throwing the error
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #4  
Old January 17th, 2013, 03:22 AM
ianhaney ianhaney is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 91 ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 23 sec
Reputation Power: 11
Hi r937

Thank you for the reply

I think this is the query that is relating to the error

$query = "SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM message WHERE poster='".$_SESSION['SESS_FIRST_NAME'] ."' ORDER BY messages_id DESC";
$result = mysql_query($query);

Reply With Quote
  #5  
Old January 17th, 2013, 04:49 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by ianhaney
I think this is the query that is relating to the error
that's the php code that generates the query

put an echo just before you execute the query, so that we can see what was actually passed to mysql that created the error

Reply With Quote
  #6  
Old January 17th, 2013, 05:12 AM
ianhaney ianhaney is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 91 ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 23 sec
Reputation Power: 11
Hi

Hope I have done it right

echo $query = "SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM message WHERE poster='".$_SESSION['SESS_FIRST_NAME'] ."' ORDER BY messages_id DESC";
$result = mysql_query($query);

Thank you for your help so far

Ian

Reply With Quote
  #7  
Old January 17th, 2013, 05:52 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by ianhaney
Hope I have done it right
that's still just php code (and i don't think it's the right call to the echo function)

what i want to see is what the echo produces, the query without the php variable stuck in it, but rather, the value of that php variable at the time of execution

Reply With Quote
  #8  
Old January 17th, 2013, 06:45 AM
ianhaney ianhaney is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 91 ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 23 sec
Reputation Power: 11
Ok might need bit of help with that as not 100% sure on what you need, is it ok to email you the file to look at, sorry for being a pain

Reply With Quote
  #9  
Old January 17th, 2013, 11:24 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by ianhaney
Ok might need bit of help with that as not 100% sure on what you need, is it ok to email you the file to look at, sorry for being a pain
no, it's not okay, sorry

read the php manual for the correct syntax for echo

then execute the echo instead of (or just prior to) executing mysql_query

echo will produce some output -- copy/paste that output here

Reply With Quote
  #10  
Old January 17th, 2013, 05:04 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 9 h 12 m 42 sec
Reputation Power: 7053
PHP Code:
echo $query "SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM message WHERE poster='".$_SESSION['SESS_FIRST_NAME'] ."' ORDER BY messages_id DESC"

Should execute fine; when it does (ie: when you save the code / upload it / visit it in your browser), it will output the actual SQL query that is being run. That output is what he needs to see.

Reply With Quote
  #11  
Old January 17th, 2013, 05:57 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 49 sec
Reputation Power: 4140
Quote:
Originally Posted by E-Oreo
Should execute fine
huge disclaimer: i don't do php

doesn't echo take a string argument? this seems to be passing an assignment, not a string

but if you say it works, great

i just wanna see the final query string, because, going back to post #1, the problem is the value passed as "session first name" -- i'm guessing it contains a single quote

Reply With Quote
  #12  
Old January 17th, 2013, 06:19 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 9 h 12 m 42 sec
Reputation Power: 7053
Quote:
doesn't echo take a string argument? this seems to be passing an assignment, not a string

Yep that's true; but in PHP an assignment is an expression that evaluates to whatever value was assigned, and due to order of operations the assignment happens before the echo, so echo actually does end up getting a string argument in this case. Normally you wouldn't write code like that though because it's confusing to read...

Quote:
i just wanna see the final query string, because, going back to post #1, the problem is the value passed as "session first name" -- i'm guessing it contains a single quote

That's my feeling as well... actually the fix probably just involves changing the PHP for the query to:
PHP Code:
 $query "SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM message WHERE poster='" mysql_real_escape_string($_SESSION['SESS_FIRST_NAME']) ."' ORDER BY messages_id DESC"


Although if the problem exists here it almost certainly exists elsewhere in the code too.

Reply With Quote
  #13  
Old January 18th, 2013, 02:07 AM
ianhaney ianhaney is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 91 ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 23 sec
Reputation Power: 11
I changed the coding to the following but still got the error so it must be elsewhere as well in another file or something

$query = "SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM message WHERE poster='".mysql_real_escape_string($_SESSION['SESS_FIRST_NAME']) . "' ORDER BY messages_id DESC"

Reply With Quote
  #14  
Old January 18th, 2013, 02:14 AM
ianhaney ianhaney is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 91 ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level)ianhaney User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 23 sec
Reputation Power: 11
It's fixed, I had the following in the coding still

echo $query; exit();

so took that out and works perfect now so if I get the error elsewhere on another page etc, I just change the coding to the following

$query = "SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM message WHERE poster='" . mysql_real_escape_string($_SESSION['SESS_FIRST_NAME']) ."' ORDER BY messages_id DESC";
$result = mysql_query($query);

Is that right?

Thank you so much

Ian

Reply With Quote
  #15  
Old January 18th, 2013, 02:21 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
Please don't post in multiple forums, at least not without mentioning in one or other of them that that's what you've done.

And believe it or not most people here are looking for help with MySQL so next time try to provide a more informative thread title.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > MySQL help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap