Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2013, 05:04 AM   PM User | #1
Bobafart
Regular Coder

 
Join Date: Dec 2006
Posts: 416
Thanks: 168
Thanked 1 Time in 1 Post
Bobafart is on a distinguished road
no element found - SQL statement looks good though

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,$pro posed_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,$pro posed_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.
Bobafart is offline   Reply With Quote
Old 01-18-2013, 06:25 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-18-2013, 08:09 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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,
Quote:
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:
Code:
$resultInsert=mysql_query($sqlInsert) or die( mysql_error() );
and then presumably you will see the error message your are getting from the query.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-18-2013, 09:16 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Code:
(id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,propo sedRot,proposed_sched_main_id,timeStampedProposal,randomHash)
                                                                                                    ^


I missed that it said firebug there too. Yep, useless on server side code, for that you need to use a debugger.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-18-2013, 09:40 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-18-2013, 09:49 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Oh I see what you mean. That's certainly possible then yes.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:02 PM.


Advertisement
Log in to turn off these ads.