jmekelb Posted August 26, 2009 Share Posted August 26, 2009 Hello, I'm having trouble with the code below. I have this exact same code on a different site with a different database and it works fine. I also have multiple tables within this database that are used for other sites and those are working fine as well. With this code, I get the "Error querying database" every time. I'm at a loss. Variables: $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $phone = $_POST['phone']; $email = $_POST['email']; $use = $_POST['use']; Query (table name is jtm): $query = "INSERT INTO jtm (firstname, lastname, phone, email, use) VALUES ('$firstname', '$lastname', '$phone', '$email', '$use') "; $result = mysqli_query($dbc, $query) or die('Error querying database'); Quote Link to comment https://forums.phpfreaks.com/topic/172023-solved-mysql-insert-help/ Share on other sites More sharing options...
mikesta707 Posted August 26, 2009 Share Posted August 26, 2009 well, it would help if you showed an actual mysql error change your last line to $result = mysqli_query($dbc, $query) or die('Error querying database ' . mysql_error()); and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/172023-solved-mysql-insert-help/#findComment-907092 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2009 Share Posted August 26, 2009 How about using mysqli_error($dbc) inside the die() statement to see why the query failed? Quote Link to comment https://forums.phpfreaks.com/topic/172023-solved-mysql-insert-help/#findComment-907095 Share on other sites More sharing options...
mikesta707 Posted August 26, 2009 Share Posted August 26, 2009 oops totally missed the i, yeah thats a much better idea Quote Link to comment https://forums.phpfreaks.com/topic/172023-solved-mysql-insert-help/#findComment-907098 Share on other sites More sharing options...
jmekelb Posted August 26, 2009 Author Share Posted August 26, 2009 You guys are awesome! As it turns out, it seems 'use' doesn't play well as a variable and the mysql_error($dbc) helped me see that. I changed it to 'comments' and it works perfectly. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/172023-solved-mysql-insert-help/#findComment-907101 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.