teknospr Posted July 22, 2011 Share Posted July 22, 2011 Good day: Im trying to insert some information in a database. The information is passing from one page to the other as evidenced by the echo I did to test this. But it is not inserting in the database and it says error, empty query. Here is the code: <html> <?php $aid = $_GET['aid']; $uid = $_GET['uid']; $page='sample.php'; ?> <body bgColor="#FFFFFF"> <meta http-equiv="refresh" content="25; url=<?php echo $page."?aid=".$aid; ?>"> <?php $con = mysql_connect("xxxxxxxx","xxxxxxxx","xxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxxxxxl", $con); $mysql="INSERT INTO visits (name, initial, last, secondlast, plate, brand, model, color, uid, homeid, purpose, guard) VALUES ('$_POST[nombre]', '$_POST[inicial]', '$_POST[apellido]', '$_POST[apellido2]', '$_POST[tablilla]', '$_POST[marca]', '$_POST[modelo]', '$_POST[color]', '$uid', '$_POST[hid]', '$_POST[purpose]', '$aid')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Visita agregada"; mysql_close($con) ?> </body> </html> Any help will be appreciated. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/242625-query-empty/ Share on other sites More sharing options...
gristoi Posted July 22, 2011 Share Posted July 22, 2011 if (!mysql_query($sql,$con)) should be if (!mysql_query($mysql,$con)) Quote Link to comment https://forums.phpfreaks.com/topic/242625-query-empty/#findComment-1246097 Share on other sites More sharing options...
IrOnMaSk Posted July 22, 2011 Share Posted July 22, 2011 Tek, i'm guessing that you have like a form page where users enter info then click submit then your php would insert the data into the database. Post that form page code too. Most likely looks like the data never got passed through your $_POST... and your VALUEs in the INSERT statement are not corrected (ah looks like it have to see your variables in the form)... And why you using both the $_GET and the $_POST superglobal variables? waiting for all your code Quote Link to comment https://forums.phpfreaks.com/topic/242625-query-empty/#findComment-1246261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.