MySQL Forums
Forum List  »  Newbie

multiple select and one insert?
Posted by: Abdo Boriz
Date: November 27, 2010 01:15PM

I appologize that I have to post this again to get some help. Please let me know if my code is correct and if not, please suggest how I can improve it. This is just a class project so it doesnt really have to be fancy but I just want to see some insert to take place somehow. Please help me so I can focus on my finals.

My code supposed to select some fields from those tables and insert in the enrollment table based on primary key that was entered in the textbox:

The problem I am having is that it's not extracting the desired fields from those tables. It's inserting 0s for integers, incrementing the enrollment auto increment number, but the rest of the fields are blank. As you can see, I have 5 SELECTs and 1 insert. Is this correct, is there is better way?

<?php

include'dbConnectionFile2.php';

$instudID=$_POST['inputstudID'];
$incourseNum=$_POST['inputcourseNum'];
$infacID=$_POST['inputfacID'];
$insessionID=$_POST['inputsessionID'];
$inclassroomID=$_POST["inputclassroomID"];


if (!$_POST['submit']) {
echo "Please fill out all five text boxes and press Submit Query button to register a student.";
}
else
{

$squery="SELECT studID, fname, lname FROM student WHERE studID=".$instudID;
$sresult=mysql_query($squery);

while($studinfo=mysql_fetch_array($sresult))
{
}
$cquery="SELECT courseNum, days, time, description, credits FROM course WHERE courseNum=".$incourseNum;
$cresult=mysql_query($cquery);

while($courseinfo=mysql_fetch_array($cresult))
{
}
$fquery="SELECT facID, fname, lname FROM faculty WHERE facID=".$infacID;
$fresult=mysql_query($fquery);

while($facinfo=mysql_fetch_array($fresult))
{
}
$ssquery="SELECT sessionID, session FROM term WHERE sessionID=".$insessionID;
$ssresult=mysql_query($ssquery);

while($sessioninfo=mysql_fetch_array($ssresult))
{
}
$lquery="SELECT classroomID, Building FROM location WHERE classroomID=".$inclassroomID;
$lresult=mysql_query($lquery);

while($locinfo=mysql_fetch_array($lresult))
{
}
mysql_query ("INSERT INTO enrollment (`enrollmentNum`, `studID`, `fname`,`lname`, `courseNum`, `days`,`time`,
`description`, `credits`,`facID`, `ffname`, `flname`,`sessionID`, `session`, `classroomID`, Building)
VALUES('.NULL.', '.$studinfo[studID].', '.$studinfo[fname].','.$studinfo[lname].', '.$courseinfo[courseNum].',
'.$courseinfo[days].', '.$courseinfo[time].', '.$courseinfo[description].', '.$courseinfo[credits].', '.$facinfo[facID].',
'.$facinfo[fname].', '.$facinfo[lname].','.$sessioninfo[sessionID].', '.$sessioninfo[session].', '.$locinfo[classroomID].',
'.$locinfo[Building].')") or die(mysql_error());
}
echo "The student has been registered successfully";
echo "<br />";
echo "<br />";
echo ("<a href=enrollment.php>Return to the enrollment list</a>");

?>



Edited 1 time(s). Last edit at 11/27/2010 01:20PM by Abdo Boriz.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.