Jump to content

[SOLVED] 2nd pair of eyes :: insert fails here


RyanSF07

Recommended Posts

Hi Guys,

 

The script below is failing to insert. Can you see where this is breaking?

The SQL table and rows are:

 

Table: classes

Rows:

id 

teacher_username

teacher_code

class_id

student_name

student_email

date

 

Here is the code -- I'm getting the "Sorry can't be completed at this time" message -- and nothing inserts.

 

Thank you for your help!

Ryan

 

<?php
session_start(); 
include_once ("contentdb.php");

include_once ("nav_home.inc");

if ($_POST[submit]) {

// php validation 
if ($_POST[teacher_username] <> "") {
	$a = TRUE;
} else {
	$a = FALSE;
	$content .= "<p>Please enter teacher username.</p>\n";
}

if ($_POST[teacher_code] <> "") {
	$b = TRUE;
} else {
	$b = FALSE;
	$content .= "<p>Please enter your teacher code.</p>\n";
}
if ($_POST[class_id] <> "") {
	$c = TRUE;
} else {
	$c = FALSE;
	$content .= "<p>Please enter your class ID.</p>\n";
}
if ($_POST[student_name] <> "") {
	$d = TRUE;
} else {
	$d = FALSE;
	$content .= "<p>Please enter your name.</p>\n";
}
if ($_POST[student_email] <> "") {
	$e = TRUE;
} else {
	$e = FALSE;
	$content .= "<p>Please enter your email address.</p>\n";
}

if ($a AND $b AND $c AND $d AND $e) { 

	$sql = "INSERT INTO classes (id, teacher_username, teacher_code, class_id, student_name, student_email, date) VALUES ('0', '$_POST[teacher_username]', '$_POST[teacher_code]', '$_POST[class_id]', '$_POST[student_name]', '$_POST[student_email]', NOW())";


	if (mysql_query($query)) {


$content .= "
<h1>Thank you!</h1>
<h2>Your information was successfully uploaded.</h2>

<br><br>
<br><br>";
}

else {

$content .="<p>We're sorry, but your info can't be uploaded at this time.<br><br><br><br></p>";
		}			

} else {  


$content .= "
<p>Please press your [back] button and fill out all fields.</p>
<br><br><br><br>";
}
}
include_once ("template_join_processor.inc"); 

?>

Link to comment
Share on other sites

Change:

$content .="<p>We're sorry, but your info can't be uploaded at this time.<br><br><br><br></p>";

to:

$content .="<p>We're sorry, but your info can't be uploaded at this time. ".mysql_error()."<br><br><br><br></p>";

Link to comment
Share on other sites

Thanks KingPhilip,

 

This is what I get:

We're sorry, but your info can't be uploaded at this time. Query was empty

 

This is the form that is sending the info -- I know it's sending to the right page because if I leave all the field blank and click "send," I get all of the validation messages.

 

Thanks again for your help:

 

$content .= "
<form action = \"join_processor.php\" method = \"post\">
<table>

<tr>
<td><p>Teacher Username:</p></td>
<td><input type = \"text\" name = \"teacher_username\" size = \"30\"  maxlength = \"30\"></td>
</tr>
<tr>
<td><p>Teacher Code:</p></td>
<td><input type = \"text\" name = \"teacher_code\" size = \"30\"  maxlength = \"30\"></td>
</tr>
<tr>
<td><p>Class ID:</p></td>
<td><input type = \"text\" name = \"class_id\" size = \"30\"  maxlength = \"30\"></td>
</tr>
<tr>
<td><p>Your Name:</p></td>
<td><input type = \"text\" name = \"student_name\" size = \"30\"  maxlength = \"30\"></td>
</tr>
<tr>
<td><p>Your Email Address:</p></td>
<td><input type = \"text\" name = \"student_email\" size = \"30\"  maxlength = \"30\"></td>
</tr>
<tr>
<td colspan = \"2\"><br>
<input type = \"submit\" name = \"submit\" value = \"Send\">
</td>
</tr>
</table>
</form>

";

Link to comment
Share on other sites

if ($a AND $b AND $c AND $d AND $e) {

     

      $sql = "INSERT INTO classes (id, teacher_username, teacher_code, class_id, student_name, student_email, date) VALUES ('0', '$_POST[teacher_username]', '$_POST[teacher_code]', '$_POST[class_id]', '$_POST[student_name]', '$_POST[student_email]', NOW())";

 

     

      if (mysql_query($query)) {

 

shouldnt the bottom line be if(mysql_query($sql)) {

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.