...

View Full Version : no element found - SQL statement looks good though



Bobafart
01-18-2013, 05:04 AM
anyone see what is wrong with this line of code? using php/mysql

$sqlInsert="INSERT INTO sched_trades_proposed (id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,propo sedRot,proposed_sched_main_id,timeStampedProposal,randomHash) VALUES('','".$originalDate."',".$_SESSION[userid].",$originalRotation,$original_sched_main_id,'".$proposedDate."',$proposedRad,$proposedRotation,$proposed_sched_main_id,UNIX_TIMESTAMP(),'".$randomHash."')";



firebug says "no element found" and points to this INSERT statement. I dont see anything wrong with the insert statement. I realize firebug isn't server side. I am still trying to solve the error though. If I comment out this line of code I get no error.


the surrounding code is:

$randomHash=sha1(rand(1,1000));
$sqlInsert="INSERT INTO sched_trades_proposed (id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,propo sedRot,proposed_sched_main_id,timeStampedProposal,randomHash) VALUES('','".$originalDate."',".$_SESSION[userid].",$originalRotation,$original_sched_main_id,'".$proposedDate."',$proposedRad,$proposedRotation,$proposed_sched_main_id,UNIX_TIMESTAMP(),'".$randomHash."')";
echo '<p>'.$sqlInsert;
$resultInsert=mysql_query($sqlInsert);


when I manually insert the INSERT statement into mySQL it gives no errors...But I am getting while trying through the web page?

Here is an example with data in the outputted INSERT statement which all looks good:

INSERT INTO sched_trades_proposed (id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,propo sedRot,proposed_sched_main_id,timeStampedProposal,randomHash) VALUES('','2013-01-10',10,7,710,'2013-01-14',3,19,723,UNIX_TIMESTAMP(),'f33f7ae89c2c6ab8e29a3cb0a97bb1f9456aacba')


FYI: the original id is auto incremented, so I insert a '' as the first column which is kosher.

Fou-Lu
01-18-2013, 06:25 AM
You don't do anything to detect errors from the mysql_query call.
You have a space in one of your property names. You must enclose it in backticks if you intend to use spaces or reserved words (I wouldn't recommend you use either).

Old Pedant
01-18-2013, 08:09 PM
First of all, you can't use FireBug to debug PHP code.

It will only find errors in the HTML/JavaScript code *PRODUCED* by PHP.

So all FireBug is saying is that your PHP code produced something incorrectly. Nearly useless information.

Secondly,

the original id is auto incremented, so I insert a '' as the first column which is kosher.

Well, no, it's really not. It's kind of like a Reformed Jew eating bacon. It's allowed even if frowned upon. The Orthodox answer is that you *MUST* use the keyword NULL there. Or, better, just omit the id field and its value from the INSERT completely.

*************

I don't see the space-in-a-field name that FouLu is referring to. I think it's just because your text lines are too long.

But in any case, what FouLu is saying is do this:

$resultInsert=mysql_query($sqlInsert) or die( mysql_error() );

and then presumably you will see the error message your are getting from the query.

Fou-Lu
01-18-2013, 09:16 PM
(id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,propo sedRot,proposed_sched_main_id,timeStampedProposal,randomHash)
^

:D

I missed that it said firebug there too. Yep, useless on server side code, for that you need to use a debugger.

Old Pedant
01-18-2013, 09:40 PM
I would bet that space was put there by this forum software.

It does that with too-long lines. And sometimes it just seems to do it arbitrarily.

Fou-Lu
01-18-2013, 09:49 PM
Oh I see what you mean. That's certainly possible then yes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum