473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating bridge table for combine two other table

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
0 1106

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

Similar topics

0
by: CoOL! . | last post by:
Hello, I found the key to solve this problem in: http://darkstar.ist.utl.pt/mysql/doc/en/InnoDB_foreign_key_constraints.html You'll probably need an INDEX for that new foreign key you are...
4
by: Matt | last post by:
Hi all, We recently upsized two Microsoft Access Databases to SQL. We're using an ADP (2002) as the front end. All the conversion issues have been resolved, except for one: Whenever we...
0
by: Symphony | last post by:
Hi, all: In our web application(vb.net), we are using Table, Table Row, Table Cell web controls dymanically load data, we define two columns, left column likes header, list data titles(eg....
2
by: David Bradbury | last post by:
I currently have an iframe on a webpage into which users can insert content. They can further customise the text as I've included buttons such as Bold, Italic, Bullet point etc. This is done along...
6
by: Ken | last post by:
I have a table I am trying to create with a unique Pk Table fields JobID---PK JobDate I would like to have the primary key be a combination of increment number starting with 001 and year and...
5
by: poppy | last post by:
I have a dataset which has 1 table with 10 coloumns and n rows. I create a new table "newTable" which contains 2 columns "A" and "B". I want to copy the contents of col 7 and col 8 of the...
3
by: steve | last post by:
Hello, I am having a problem with an index controlled partitioned table. I was altering a table using SQL. I was trying to add a partition to a table to change it from index controlled to...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
3
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but...
10
by: pbd22 | last post by:
Hi. Like the title says - how do i do this? I was given the following example: INSERT INTO TABLE2 SELECT * FROM TABLE1 WHERE COL1 = 'A' The above statement threw the following error:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.