Jump to content

MYSQL Error code:


timothyltaylor

Recommended Posts

Can anyone help me figure out why nothing is going into the database from this end?
I would really appreciate it! (specifically in the "mysql_query("INSERT INTO" statement)
  Thank you...

Here's my code:
[code]<?
$classdateandlocation=$_POST['classdateandlocation'];
$instructors=$_POST['instructors'];
$comments=$_POST['comments'];
$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$phone=$_POST['phone'];

$Q1=$_POST['Q1'];
$Q2=$_POST['Q2'];
$Q3=$_POST['Q3'];
$Q4=$_POST['Q4'];
$Q5=$_POST['Q5'];
$Q6=$_POST['Q6'];
$Q7=$_POST['Q7'];
$Q8=$_POST['Q8'];
$Q9=$_POST['Q9'];

}
if(trim($_POST['classdateandlocation']) == "") {
  die("*No <b>Class Date and Location</b> was entered, please click back button and fill in required fields");
}
if(trim($_POST['instructors']) == "") {
  die("*No <b>Instructors</b> were entered, please click back button and fill in required fields");
}
if(trim($_POST['comments']) == "") {
  die("*No <b>Comments</b> were entered, please click back button and fill in required fields");
}
if(trim($_POST['name']) == "") {
  die("*No <b>Name<b/> was entered, please click back button and fill in required fields");
}
if(trim($_POST['address']) == "") {
  die("*No <b>Address</b> was entered, please click back button and fill in required fields");
}
if(trim($_POST['city']) == "") {
  die("*No <b>City<b/> was entered, please click back button and fill in required fields");
}
if(trim($_POST['state']) == "") {
  die("*No <b>State</b> was entered, please click back button and fill in required fields");
}
if(trim($_POST['zip']) == "") {
  die("*No <b>Zip</b> was entered, please click back button and fill in required fields");
}
if(trim($_POST['phone']) == "") {
  die("*No <b>Phone</b> was entered, please click back button and fill in required fields");
}
if(trim($_POST['Q1']) == "") {
  die("<b>*Question 1<b/> wasn't filled out, please click back button and fill in required fields");
}

mysql_connect("mysite.com", "xxxxxxx", "xxxxxxxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxx_com_xxxxx") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ( '$classdateandlocation', '$instructors', '$comments','$name', '$email', '$address', '$city', '$state', '$zip', '$phone')");
if(trim($_POST['classdateandlocation']) == "") {
  die("*No <b>Class Date and Location</b> was entered, please click back button and fill in required fields");

Print "Your information has been successfully added to the database.";
echo "<p>Here is what you entered:<p>";
echo "<p><b>Class Date and Location:</b> $classdateandlocation<p>";
echo "<p><b>Instructors:</b> $instructors<p>";
echo "<p><b>Comments:</b> $comments<p>";
echo "<p><b>Name:</b> $name<p>";
echo "<p><b>Email:</b> $email<p>";
echo "<p><b>Address:</b> $address<p>";
echo "<p><b>City:</b> $city<p>";
echo "<p><b>State:</b> $state<p>";
echo "<p><b>Zip:</b> $zip<p>";
echo "<p><b>Phone:</b> $phone<p>";

echo "<p><b>This learning Experience was:</b> $Q1<p>";
echo "<p><b>Were the stated learning objectives met?:</b> $Q2<p>";
echo "<p><b>If applicable, were prerequisites appropriate?:</b> $Q3<p>";
echo "<p><b>Were program materials both accurate and effective?:</b> $Q4<p>";
echo "<p><b>Did program materials contribute to the achievement of the learning Objectives?:</b> $Q5<p>";
echo "<p><b>Was the time allotted to the learning experience appropriate?:</b> $Q6<p>";
echo "<p><b>Were the facilities and/or the technological equipment appropriate?:</b> $Q7<p>";
echo "<p><b>Were the handouts and advanced preparation materials satisfactory?:</b> $Q8<p>";
echo "<p><b>Was the classroom facilitators knowledge and experience satisfactory for the course material?:</b> $Q9<p>";
   


  mail("[email protected]", "EPSA CAP2 Evaluation Results from $name", $body, $email, $headers );
?>[/code]

       Lee
Link to comment
https://forums.phpfreaks.com/topic/29966-mysql-error-code/
Share on other sites

Well save the query as a variable and add an [code]or die(mysql_error() ."<br>$query");[/code] to the end of your mysql_query statement. It helps to troubleshoot if you can see what went wrong.

Having the wrong column count is the most common problem for that type of query.
Link to comment
https://forums.phpfreaks.com/topic/29966-mysql-error-code/#findComment-137828
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.