Jump to content

Just spent an hour typing this code, getting a db query error for no reason!


jdock1

Recommended Posts

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]']; ?

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

..... 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')";

   

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.