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. 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'] ; 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); ?> 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. 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 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); ?> 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. 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
Archived
This topic is now archived and is closed to further replies.