By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

Creating bridge table for combine two other table

P: 1
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 ?
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML> <html> <head> <?php
  2. error_reporting(0);
  3. session_start();
  4. if (!isset($_SESSION['studentID']))
  5. {
  6. $_SESSION['studentID'] = $_POST['studentID'];
  7. $_SESSION['pswd'] = $_POST['pswd'];
  8. }
  9.  
  10. include("connect.php");
  11. $sql = "SELECT * FROM student WHERE 
  12. studentID='".$_SESSION['studentID']."' AND 
  13. pswd='".$_SESSION['pswd']."'";
  14.  
  15. $result = mysql_query($sql);
  16. $row = mysql_num_rows($result);
  17. if ($row == 0)
  18. {
  19. echo "Login fail Try again <a href='http://bytes.com/'>here</a>";
  20. ?> <meta http-equiv="refresh" content="0;userlogin.php" /> <?php
  21. }
  22. else
  23. {
  24. $row = mysql_fetch_assoc($result);
  25. }
  26. ?> <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
  27.  
  28. if(isset($_POST["submit"]))
  29. {
  30. session_start();
  31. include("connect.php");
  32.  
  33. $SubjectID = $_POST['SubjectID'];
  34. $SubjectName = $_POST['SubjectName'];
  35. $SubjectLecturer = $_POST['SubjectLecturer'];
  36.  
  37.  
  38. $Subject= "SELECT SubjectID
  39.             FROM Subject
  40.             WHERE SubjectID='$SubjectID'";
  41.  
  42. $queryssubject=mysql_query($subject) or die(mysql_error);
  43. $record=mysql_num_rows($querysubject);
  44.  
  45. if($record==1)
  46. {
  47.         header ('Location: studentSubject.php');
  48. }
  49. else if($record<1)
  50. {
  51.     if(substr($subjectID))
  52.     {
  53.  
  54.         $insertIntoSubject= "INSERT INTO Subject ('SubjectID', 'SubjectName', 'SubjectLecturer') VALUES ('$SubjectID','$SubjectName','$SubjectLecturer')";
  55.  
  56.         $result1=mysql_query($insertIntoSubject) or die(mysql_error());
  57.  
  58.         $insertIntobridge="INSERT INTO `bridge`(`SubjectID`, `studentID`)
  59.                             VALUES     ('$SubjectID', '$studentID')";
  60.         $result2=mysql_query($insertIntobridge)or die(mysql_error());
  61.  
  62.         $insertIntostudent="INSERT INTO student (`studentID`, `studentName`, `IC`, `studentFac`, `studentPhone`, `studentEmail`, `pswd`, `studentAddress')
  63.                         VALUES ('$studentID', '$studentName', '$IC', '$studentFac', '$studentPhone', '$studentEmail', 'abc123', '$studentAddress')";
  64.  
  65.         $result3=mysql_query($insertIntostudent)or die(mysql_error());
  66.  
  67.  
  68.  
  69.         if ($result1 && $result2 && $result3)
  70.         {
  71.             header ('Location: studentSubject.php');
  72.         }
  73.     }
  74.     else echo 'insert error';
  75. }
  76.  
  77. else
  78. {
  79. echo "<script type='text/javascript'>
  80.                             alert('Data Updated!')
  81.                             location.href='homestudent.php'
  82.                             </script>";
  83.  
  84. }
  85. mysql_close($conn);
  86. }
  87. ?>
May 14 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.