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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This is Driving me crazy!

Status
Not open for further replies.

roguegenius

Programmer
Sep 2, 2009
3
US
I keep getting a SQL error on the page and the statement that is shown as having the issue is correct as far as I can tell.

Code:
$sql_query = sprintf('INSERT into %s SET test_id="%s", user_name="%s", score=%u, date=now(), time=%u, result_ip="%s"',
TABLE_RESULTS,
SQL::esc($this->filename),
$name,
$this->res['correct_answers'],
$this->res['time_elapsed'],
$_SERVER['REMOTE_ADDR']

I am running MySQL 5.1.11
I have even tried backing up my database with compatibility mode selected and importing it back in. Nothing.
 
What error are you getting?

Have you tried echoing out the query just to check if after all the variable substitution is done it looks o.k.?


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
It loads all of the data into my database just fine. It doesn't miss a thing at all.

The error on the page is this -
insert: INSERT into results SET result_test_id="example-test", result_user_name="MyName", score="4", date= Now(), time="27", ip="xx.xx.x.xxx", 0.0077431201934814

I x'ed out my ip address but it does show correctly.

If I check the query in MySql query browser for errors, I get a 1064 syntax error. But I just don't see it for some reason.
 
That's not an error, that's just your query being printed.

date and time are reserved words, and should not be used as field names as it can lead to confusion.

Aside form that, that float at the end seems to have no field associated with it, it just a very long decimal.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If this is an error of your database library (I doubt it because there is no message), it may be that the server is configured in ANSI mode. In that case, use the right quotes for SQL strings (').

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Thanks for all of the help guys!!

My server is not configured in ANSI.
I believe it is just my query being printed out to the page, but I stupid as it sounds I have no idea on how to make it stop.
Unless I re-write the entire area.

 
So it actualy works?, which would imply that the query you get printed is nothing to do with what got executed ????.
Correct me if I'm wrong guys but isn't insert syntax
Code:
insert into table (columns) (values);
?
It has , however, been a long day !
 
Perhaps posting a bit more of code would let us see what is causing the query to be printed.

Do you see any echo or print statements around ?


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Looks like you are confusing an INSERT query with an UPDATE query. Check the manual for syntax.

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
If you are referring to the "SET" syntax, its perfectly valid syntax, as shown here:

In the second example.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
i wouldn't exactly call it "perfectly valid"

for one thing, it isn't Standard SQL :)

mysql also supports the Standard SQL syntax for the INSERT statement, so i advise people always to use that instead

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top