SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET not recognised in SQL statements

    Hi All,

    I have a couple of SQL statements which I'm struggling with. I'm passing a variable called 'lea' in the url, but when I try and 'get' it using SQL it seems to ignore it.

    I know the variable is set as if I print it to the screen it displays correctly.

    The first statement is

    Code:
    select * from table where column = '".$_GET['lea']."'
    I haven't had this problem with other similar statements.

    The other statement is an insert

    Code:
    insert into table (site_id, site_name) values ('".$_GET['lea']."','".$_POST['sitename']."')
    Again no problems with other similar statements. The insert seems to simply ignore this and insert the default value of 0, but the select returns an error stating an error in in SQL syntax:

    Code:
    select * from table where column =
    so it effectively can't see the $_GET variable?

    Any ideas?

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the actual code?

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code is just an SQL statement so I'm not sure it will help, but here you go:

    PHP Code:
    $result=mysql_query("insert into ora_details (site_id, site_name, dba_subscriber, os_used, os_version, ora_version,
                        conn_type, server_ip, server_subnet, server_gateway, ora_port_no, db_name1, db_name2, server_use,
                        ras_user, ras_pass, ras_sp_det, ras_dial, direct_dial, pc_any_user, pc_any_pass, os_user, os_pass,
                        vpn_name, vpn_user, vpn_pass, vpn_det, web_url, add_det, timestamp)
                        values
                        ('"
    .$_GET['lea']."','".$_POST['sitename']."','".$_POST['dbasub']."','".$_POST['osused']."','".$_POST['osversion']."',
                        '"
    .$_POST['oraver']."','".$_POST['conntype']."','".$_POST['serverip']."','".$_POST['serversub']."',
                        '"
    .$_POST['servergate']."','".$_POST['oraportno']."','".$_POST['dbname1']."','".$_POST['dbname2']."',
                        '"
    .$_POST['serveruse']."','".$_POST['rasuser']."','".$_POST['raspass']."','".$_POST['rasspdet']."','".$_POST['rasdial']."',
                        '"
    .$_POST['directdial']."','".$_POST['pcanyuser']."','".$_POST['pcanypass']."','".$_POST['osuser']."',
                        '"
    .$_POST['ospass']."','".$_POST['vpnname']."','".$_POST['vpnuser']."','".$_POST['vpnpass']."',
                        '"
    .$_POST['vpndet']."','".$_POST['weburl']."','".$_POST['adddet']."', now())") or die(mysql_error()); 
    This is run is there are no errors found. As I said before, the rest of the data is being inserted, but just not the first column.

  4. #4
    SitePoint Addict rokc's Avatar
    Join Date
    Oct 2004
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try echoing $_GET['lea']

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Already have (see my first post). It works fine.

    Thx anyway.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Try putting the get variable into an ordinary variable then use that in your query.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    texas
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does the variable contain a string value with the character ' in it? you might need to addslashes($_GET['lea']) to prep the value for the query
    free online calendar: http://inversiondesigns.com
    includes multiple calendars/users/groups, task manager,
    email and sms reminders, permissions (sharing), etc.

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it is just a number. In the first instance it was lea=1 in the url. This didn't insert, so I tried changing the statement to add a 1 instead of the variable and this did work.

    The column is tinyint(3) so its not expecting a string.

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Spikez,

    Thanks, I did try that, but it also didn't work.

  10. #10
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    texas
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what happens if you store that sql string as a var, $sql, and echo $sql ? maybe that'll give us more info than the mysql_error and let us see exactly what you're sending in...
    free online calendar: http://inversiondesigns.com
    includes multiple calendars/users/groups, task manager,
    email and sms reminders, permissions (sharing), etc.

  11. #11
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    If the first column is defined tinyint, maybe you should eliminate the ' around the value:

    PHP Code:
    $result=mysql_query("insert into ora_details (site_id, site_name,  dba_subscriber, os_used, os_version, ora_version, 
                        conn_type, server_ip, server_subnet, server_gateway, ora_port_no, db_name1, db_name2, server_use, 
                        ras_user, ras_pass, ras_sp_det, ras_dial, direct_dial, pc_any_user, pc_any_pass, os_user, os_pass, 
                        vpn_name, vpn_user, vpn_pass, vpn_det, web_url, add_det, timestamp) 
                        values 
                        ("
    .$_GET['lea'].",'".$_POST['sitename']."','".$_POST['dbasub']."','".$_POST['osused']."','".$_POST['osversion']."', 
                        '"
    .$_POST['oraver']."','".$_POST['conntype']."','".$_POST['serverip']."','".$_POST['serversub']."', 
                        '"
    .$_POST['servergate']."','".$_POST['oraportno']."','".$_POST['dbname1']."','".$_POST['dbname2']."', 
                        '"
    .$_POST['serveruse']."','".$_POST['rasuser']."','".$_POST['raspass']."','".$_POST['rasspdet']."','".$_POST['rasdial']."', 
                        '"
    .$_POST['directdial']."','".$_POST['pcanyuser']."','".$_POST['pcanypass']."','".$_POST['osuser']."', 
                        '"
    .$_POST['ospass']."','".$_POST['vpnname']."','".$_POST['vpnuser']."','".$_POST['vpnpass']."', 
                        '"
    .$_POST['vpndet']."','".$_POST['weburl']."','".$_POST['adddet']."', now())") or die(mysql_error()); 

  12. #12
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set error level to E_ALL

  13. #13
    SitePoint Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suspect it's a problem with your form; I assume the _GET value shows up in the query string in the URL, yes?

    How are you passing both _GET and _POST values at the same time? (It makes a difference).

    And did you try seeing if any _GET and _POST values are set with:

    Code:
    print '<pre>'; print_r($_GET); print '</pre>';
    print '<pre>'; print_r($_POST); print '</pre>';

  14. #14
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    texas
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, as long as you aren't using the same variable name in both _GET and _POST, you could just use $_REQUEST instead (which is simply the combination of _GET and _POST)
    free online calendar: http://inversiondesigns.com
    includes multiple calendars/users/groups, task manager,
    email and sms reminders, permissions (sharing), etc.

  15. #15
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all your suggestions guys.

    Fortunately I figured it out after setting error reporting to E_ALL. The $_GET['lea'] was not defined after submiting the form. This is because is only had the form action set to PHP_SELF so it was not parsing the lea variable before processing the code. I changed this to:

    PHP Code:
    <?php echo $_SERVER['PHP_SELF']."?lea=".$_GET['lea']; ?>
    and it works fine.

    Thanks again

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    oooh don't you hate those little problems!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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