jdock1 Posted September 27, 2010 Share Posted September 27, 2010 I spent the last hour or so typing this code up, and for some reason I am getting a query error. I have reviewed & revised the code up and down for the past half hour and can't seem to figure out the problem. Can someone look after this for me and tell me what I could be doing wrong? Yes, I know my code is a bit sloppy and may use bad practice techniques, but it works for me. Its a survey that I coded so I could collect data and place it on CPA ad listings. So I need this so work at some point soon. My code: <?php $user = $_POST['user']; $email = $_POST['email']; $password = $_POST['pass']; $paypal = $_POST['paypal']; $q1 = $_POST['q1[favsite]']; $q2 = $_POST['q2[isp]']; $q21 = $_POST['q2.1[bill]']; $email_services = $_POST['email_services']; $ebay = $_POST['ebay']; $amazon = $_POST['amazon']; $q6 = $_POST['q6[purchase]']; $q7 = $_POST['q7[social]']; $q8 = $_POST['q8[bookmarks]']; $q9 = $_POST['q9[search]']; $q10 = $_POST['q10[homepage]']; $q11 = $_POST['q11[5topsites]']; $q12 = $_POST['q12[state]']; if ($_POST['fin'] == "complete") { $dbc = mysqli_connect('localhost', 'root', 'password', 'database') or die('Could not connect'); $query = "INSERT INTO user_data (id, user, email, password, paypal, q1[favsite], q2[isp], q21[bill], email_services, ebay, amazon, q6[purchase], q7[social], q8[bookmarks], q9[search], q10[homepage], q11[5topsites], q12[state]) VALUES ('$user', '$email', '$password', '$paypal', '$q1', '$q2', '$q21', '$email_services', '$ebay', '$amazon', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', '$q12')"; mysqli_query($dbc,$query) or die('Error querying database'); include_once("../phpmailer/class.phpmailer.php"); $mail = new PHPMailer; $mail->ClearAddresses(); $mail->AddAddress('', ''); $mail->From = ''; $mail->FromName = ''; $mail->Subject = 'Thanks for finishing the survey!'; $mail->Body = "Hello, $user. This is a reminder that you have finished the survey and your credit is currently being processed. Please login to your account at ../../ to view the status of your credit & cash out. "; if ($mail->Send()) { echo "<center>Mail Sent.</center>"; } else { echo $mail->ErrorInfo; } echo "<center><h2>Thanks for completing the survey! Please <a href='login.php'>login</a> to your account to view the status of your credit & cash out.</h2></center>"; } ?> It has nothing to do with PHPMailer, I of course edited the variables just now so all my info wouldnt be public, but everything is fine untill you press submit & I get the or die() error message "Error querying database". What the hell did I do wrong? Is it possible that I cant name variables in the format I used with most of them ($var1 = $_POST['var[desc]']; ? Quote Link to comment https://forums.phpfreaks.com/topic/214546-just-spent-an-hour-typing-this-code-getting-a-db-query-error-for-no-reason/ Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2010 Share Posted September 27, 2010 For debugging, you should be outputting mysqli_error() in your die() statements, in addition to echoing the query string. mysqli_query($dbc,$query) or die( '<br>Query string: ' . $query . '<br>Produced error: ' . mysqli_error($dbc) ); Quote Link to comment https://forums.phpfreaks.com/topic/214546-just-spent-an-hour-typing-this-code-getting-a-db-query-error-for-no-reason/#findComment-1116439 Share on other sites More sharing options...
jdock1 Posted September 27, 2010 Author Share Posted September 27, 2010 For debugging, you should be outputting mysqli_error() in your die() statements, in addition to echoing the query string. mysqli_query($dbc,$query) or die( '<br>Query string: ' . $query . '<br>Produced error: ' . mysqli_error($dbc) ); Oh thanks! Forgot about that! Quote Link to comment https://forums.phpfreaks.com/topic/214546-just-spent-an-hour-typing-this-code-getting-a-db-query-error-for-no-reason/#findComment-1116448 Share on other sites More sharing options...
mikosiko Posted September 27, 2010 Share Posted September 27, 2010 ..... I get the or die() error message "Error querying database". What the hell did I do wrong? Is it possible that I cant name variables in the format I used with most of them ($var1 = $_POST['var[desc]']; ? Seems that you are using the wrong fields name here INSERT INTO user_data (id, user, email, password, paypal, q1[favsite], q2[isp], q21[bill], email_services, ebay, amazon, q6[purchase], q7[social], q8[bookmarks], q9[search], q10[homepage], q11[5topsites], q12[state]) VALUES ('$user', '$email', '$password', '$paypal', '$q1', '$q2', '$q21', '$email_services', '$ebay', '$amazon', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', '$q12')"; Quote Link to comment https://forums.phpfreaks.com/topic/214546-just-spent-an-hour-typing-this-code-getting-a-db-query-error-for-no-reason/#findComment-1116450 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.