mtvaran Posted November 8, 2010 Share Posted November 8, 2010 try { $sql = "SELECT StudentID,CourseID FROM student,course WHERE StudentID =" . $_POST['sid'] AND CourseID =".$_POST['cid'] ; //-----> error line $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_num_rows($query) > 0) { throw new Exception('StudentID already taken'); } } NB: basicaly im inserting data into a table from another two table field. Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/ Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 add . " after $_POST['sid'] $sql = "SELECT StudentID,CourseID FROM student,course WHERE StudentID =" . $_POST['sid'] . " AND CourseID =".$_POST['cid'] ; Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/#findComment-1131835 Share on other sites More sharing options...
mtvaran Posted November 8, 2010 Author Share Posted November 8, 2010 still i get error msg. im bit new & stupid with php. so i just post all of my coding so could any1 check this for me plss <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); try { $sql = "SELECT StudentID,CourseID FROM take WHERE StudentID =" . $_POST['sid'] . " AND CourseID =" .$_POST['cid'] ; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_num_rows($query) > 0) { echo'StudentID already taken'; } } if (!empty($_POST['sid']) && !empty($_POST['cid'])) //-------> error line { $ct = 0; $student = $_POST['sid']; foreach ($_POST['cid'] as $key => $course) { $sql = "INSERT INTO take (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."','".mysql_real_escape_string($course)."')"; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows() > 0){$ct++;} } echo $ct . ' rows added.'; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/#findComment-1131847 Share on other sites More sharing options...
Pikachu2000 Posted November 8, 2010 Share Posted November 8, 2010 It would be helpful to also post the error message. Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/#findComment-1131849 Share on other sites More sharing options...
mtvaran Posted November 8, 2010 Author Share Posted November 8, 2010 this is the error msg.... Parse error: parse error, expecting `T_CATCH' in Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/#findComment-1131851 Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); try { $sql = "SELECT StudentID,CourseID FROM take WHERE StudentID =" . $_POST['sid'] . " AND CourseID =" .$_POST['cid'] ; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_num_rows($query) > 0) { echo'StudentID already taken'; } } if (!empty($_POST['sid']) && !empty($_POST['cid'])) //-------> error line { $ct = 0; $student = $_POST['sid']; foreach ($_POST['cid'] as $key => $course) { $sql = "INSERT INTO take (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."','".mysql_real_escape_string($course)."')"; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows() > 0){$ct++;} } echo $ct . ' rows added.'; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/#findComment-1131853 Share on other sites More sharing options...
radar Posted November 8, 2010 Share Posted November 8, 2010 // sql query was here, new code supplied shows new error. Quote Link to comment https://forums.phpfreaks.com/topic/218122-anyone-check-this-code-plss/#findComment-1131854 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.