Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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:
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Oh I see what you mean. That's certainly possible then yes.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •