$_GET not being recognised by SQL statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

$_GET not being recognised by SQL statements

Post by TheOracle »

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 all

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

The other statement is an insert

Code: Select all

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 all

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

Any ideas?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

Show the complete code ;)
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

This is the statement which is passed when no errors are found.

Code: Select all

$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());
As I said before, it inserts all the data, but puts the default value of 0 into the site_id column. I have tried this when the lea=1 in the url and it doesn't work, but when I replace the varibale in the insert with the number 1 it does work?

Any other ideas?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

change this '".$_GET['lea']."' for '.$_GET['lea'].' (i remove double quotes)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

quick guess here, maybe 'lea' technically doesn't exist? Do a

Code: Select all

var_export($_GET)
to see.
Post Reply