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'); 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. 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? 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 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! Link to comment https://forums.phpfreaks.com/topic/172023-solved-mysql-insert-help/#findComment-907101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.