Cooper94 Posted September 18, 2009 Share Posted September 18, 2009 I get a error that is: Error: Query was empty Any help will be greatful, code is on the bottom and thank you again for your help guys! <?php if(isset($_POST['contact'])) { include 'db.php'; $name = $_POST['name']; $email = $_POST['email']; $to = $_POST['to']; $comments = $_POST['comments']; $today = date("Y-m-d"); $name = mysql_real_escape_string($name); $email = mysql_real_escape_string($email); $to = mysql_real_escape_string($to); $comments = mysql_real_escape_string($comments); $sql=mysql_query("INSERT INTO contact (from,date,to,comments,email) VALUES ('$name','$today','$to','$comments','$email')"); if (!mysql_query($sql,$connection)) { die('Error: ' . mysql_error()); } } ?> Link to comment https://forums.phpfreaks.com/topic/174737-error-query-was-empty/ Share on other sites More sharing options...
Garethp Posted September 18, 2009 Share Posted September 18, 2009 Change if (!mysql_query($sql,$connection)) To if(!sql) Link to comment https://forums.phpfreaks.com/topic/174737-error-query-was-empty/#findComment-920871 Share on other sites More sharing options...
Cooper94 Posted September 18, 2009 Author Share Posted September 18, 2009 No error pops up but it still dosnt populate the database. Thank You Link to comment https://forums.phpfreaks.com/topic/174737-error-query-was-empty/#findComment-920873 Share on other sites More sharing options...
knsito Posted September 18, 2009 Share Posted September 18, 2009 I think you also need to wrap your field names with ` (grave accent - on the ~[tilda] ie: `from`,`to`, ... etc as these are keywords in sql Link to comment https://forums.phpfreaks.com/topic/174737-error-query-was-empty/#findComment-920874 Share on other sites More sharing options...
Cooper94 Posted September 18, 2009 Author Share Posted September 18, 2009 Thank you so much! Link to comment https://forums.phpfreaks.com/topic/174737-error-query-was-empty/#findComment-920875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.