Creating bridge table for combine two other table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zati
    New Member
    • May 2014
    • 1

    Creating bridge table for combine two other table

    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,,stud entName,IC,stud entFac,studentP hone,studentEma il,pswd,student Address. 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 ?
    Code:
    <!DOCTYPE HTML> <html> <head> <?php
    error_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> <?php
    
    if(isset($_POST["submit"]))
    {
    session_start();
    include("connect.php");
    
    $SubjectID = $_POST['SubjectID'];
    $SubjectName = $_POST['SubjectName'];
    $SubjectLecturer = $_POST['SubjectLecturer'];
    
    
    $Subject= "SELECT SubjectID
    			FROM Subject
    			WHERE 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);
    }
    ?>
    Last edited by Rabbit; May 14 '14, 04:24 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...