rmmo Posted July 3, 2008 Share Posted July 3, 2008 ok so this code is supposed to insert data into my orders table... but first i need to find my cust_id from the customer table as it is a feild in the orders table... why isnt the sql select query working??? it just goes to my error trigger?! can anyone see where i have gone wrong? $conn = mysql_connect($host, $dbuser, $dbpass) or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db($dbname, $conn) or trigger_error("SQL", E_USER_ERROR); $name = $_SESSION['name']; $password = $_SESSION['password']; echo $name; echo $password; $checkcustid= ("select customer_id from customer where customer_name = $name and customer_password = $password"); // $insertorder = mysql_query("insert into custorder values('',''"); // echo $name, "your order has been processed below is your recipt. please printscreen this page to use as proof of purchase."; //foreach ($_POST as $value => $key) // { // echo $value, '<br/>'; // insert into table here //} $results = mysql_query($checkcustid, $conn) or trigger_error("SQL", E_USER_ERROR); echo $results; ?> Link to comment https://forums.phpfreaks.com/topic/113135-solved-weird-sql-error-can-anyone-see-where-im-going-wrong/ Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 You should use mysql_error() somewhere to find out what the error is. I would guess that $name or $password has a bad character in it or something. Link to comment https://forums.phpfreaks.com/topic/113135-solved-weird-sql-error-can-anyone-see-where-im-going-wrong/#findComment-581230 Share on other sites More sharing options...
rmmo Posted July 3, 2008 Author Share Posted July 3, 2008 $checkcustid= ("select customer_id from customer where customer_name = $name and customer_password = $password"); should have had the $name as '$name' and $password as '$password'. so now there is no slq error but my $results variable isnt showing what i had hoped! i was hoping for a "customer_id" from my customer table but it is infact showing "Resource id #3" and i have NO IDEA where thats coming from! could it be that this is returning an array? i have no idea how to get my actual table data... i only need the one feild so that i can assign it to another variable for an insert statement! PLEASE can someone explain why this is happening?! thanks a million! in advanced RMMO Link to comment https://forums.phpfreaks.com/topic/113135-solved-weird-sql-error-can-anyone-see-where-im-going-wrong/#findComment-581258 Share on other sites More sharing options...
teynon Posted July 3, 2008 Share Posted July 3, 2008 You need to view the results. $query=mysql_query("select customer_id from customer where customer_name = '$name' and customer_password = '$password'"); while ($req=mysql_fetch_array($query)) { print_r($req); } Link to comment https://forums.phpfreaks.com/topic/113135-solved-weird-sql-error-can-anyone-see-where-im-going-wrong/#findComment-581269 Share on other sites More sharing options...
rmmo Posted July 3, 2008 Author Share Posted July 3, 2008 thanks alot teynon! thats exactly what i was after! much appreciated! RMMO <SOLVED> thanks to all especially teynon Link to comment https://forums.phpfreaks.com/topic/113135-solved-weird-sql-error-can-anyone-see-where-im-going-wrong/#findComment-581306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.