Jump to content

Recommended Posts

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> <?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);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/288473-creating-bridge-table-in-mysql/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.