zati Posted May 14, 2014 Share Posted May 14, 2014 HI. Im new to database. I didnt know how to use bridge table. In my bridge table i have SubjectID and studentID, PK from student table and subject table. In my subject table have SubjectID, SubjectName and SubjectLecturer while in my student table have studentID,,studentName,IC,studentFac,studentPhone, studentEmail,pswd,studentAddress. I didnt know where is the wrong part because when i click my form which is enroll button, this enroll page blank Can someone check my coding ? Help ? <!DOCTYPE HTML> <html> <head> <?phperror_reporting(0);session_start();if (!isset($_SESSION['studentID'])){$_SESSION['studentID'] = $_POST['studentID'];$_SESSION['pswd'] = $_POST['pswd'];}include("connect.php");$sql = "SELECT * FROM student WHERE studentID='".$_SESSION['studentID']."' AND pswd='".$_SESSION['pswd']."'";$result = mysql_query($sql);$row = mysql_num_rows($result);if ($row == 0){echo "Login fail Try again <a href='http://bytes.com/'>here</a>";?> <meta http-equiv="refresh" content="0;userlogin.php" /> <?php}else{$row = mysql_fetch_assoc($result);}?> <meta charset="UTF-8"> <title>E-Education portal</title> <link href="http://bytes.com/style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="header"></ div> <?phpif(isset($_POST["submit"])){session_start();include("connect.php");$SubjectID = $_POST['SubjectID'];$SubjectName = $_POST['SubjectName'];$SubjectLecturer = $_POST['SubjectLecturer'];$Subject= "SELECT SubjectIDFROM SubjectWHERE SubjectID='$SubjectID'";$queryssubject=mysql_query($subject) or die(mysql_error);$record=mysql_num_rows($querysubject);if($record==1){header ('Location: studentSubject.php');}else if($record<1){if(substr($subjectID)){$insertIntoSubject= "INSERT INTO Subject ('SubjectID', 'SubjectName', 'SubjectLecturer') VALUES ('$SubjectID','$SubjectName','$SubjectLecturer')";$result1=mysql_query($insertIntoSubject) or die(mysql_error());$insertIntobridge="INSERT INTO `bridge`(`SubjectID`, `studentID`)VALUES ('$SubjectID', '$studentID')";$result2=mysql_query($insertIntobridge)or die(mysql_error());$insertIntostudent="INSERT INTO student (`studentID`, `studentName`, `IC`, `studentFac`, `studentPhone`, `studentEmail`, `pswd`, `studentAddress')VALUES ('$studentID', '$studentName', '$IC', '$studentFac', '$studentPhone', '$studentEmail', 'abc123', '$studentAddress')";$result3=mysql_query($insertIntostudent)or die(mysql_error());if ($result1 && $result2 && $result3){header ('Location: studentSubject.php');}}else echo 'insert error';}else{echo "<script type='text/javascript'>alert('Data Updated!')location.href='homestudent.php'</script>";}mysql_close($conn);}?> Link to comment https://forums.phpfreaks.com/topic/288473-creating-bridge-table-in-mysql/ Share on other sites More sharing options...
Barand Posted May 14, 2014 Share Posted May 14, 2014 If you have problems it is not a good idea to start off by switching error reporting off Link to comment https://forums.phpfreaks.com/topic/288473-creating-bridge-table-in-mysql/#findComment-1479483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.