RyanSF07 Posted July 2, 2009 Share Posted July 2, 2009 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/ Share on other sites More sharing options...
Philip Posted July 2, 2009 Share Posted July 2, 2009 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867486 Share on other sites More sharing options...
arneman Posted July 2, 2009 Share Posted July 2, 2009 Do you get any type of error, or does it just do nothing at all? Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867489 Share on other sites More sharing options...
RyanSF07 Posted July 2, 2009 Author Share Posted July 2, 2009 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> "; Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867501 Share on other sites More sharing options...
blueman378 Posted July 2, 2009 Share Posted July 2, 2009 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)) { Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867505 Share on other sites More sharing options...
RyanSF07 Posted July 2, 2009 Author Share Posted July 2, 2009 Thanks Man, That's exactly what I needed -- second pair of eyes. Cheers, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867508 Share on other sites More sharing options...
blueman378 Posted July 2, 2009 Share Posted July 2, 2009 your welcome interesting looking project btw. Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867509 Share on other sites More sharing options...
pkedpker Posted July 2, 2009 Share Posted July 2, 2009 lol i noticed your using the old school BASIC like AND tags.. if ($a AND $b AND $c AND $d AND $e) { could just be if ($a && $b && $c && $d && $e) { not that it helps much since it's solved Quote Link to comment https://forums.phpfreaks.com/topic/164455-solved-2nd-pair-of-eyes-insert-fails-here/#findComment-867514 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.