Hi

I think your mysql_query is wrong. You need to include the $db variable
in the query otherwise it doesn't know where to put the stuff.

$result = mysql_query($sql, $db);

Cheers
JD

-----Original Message-----
From: Chiew, Richard [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 25, 2002 6:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] PHP Forms


I have the following php code to asks for a new student to fill out a
registration form.  Using php, take what the user enters and put it into
the "students" table. But when i select * from students in mysql, it
didn't show, why?
 
<HTML>
<BODY bgColor=#ffffff>
<?php
if ($submit) {
  // process form
  $db = mysql_connect ("localhost", "root", "mollier");
  $select=mysql_select_db ("mydb"); 
  $sql = "INSERT INTO students 
(student_id, firstname,lastname, address) VALUES 
('$student_id', '$firstname', '$lastname', '$address')";
  $result = mysql_query($sql);
  echo "Thank you! Information entered.\n";
} else{
 
  // display form
 
  ?>
<FORM onsubmit="return formvalidation(this)" 
action="<?php echo $PHP_SELF?>"
method=post><INPUT type=hidden value="New Student Registration - BBS" 
name=FORM_NAME> 
<P style="LINE-HEIGHT: 100%; BACKGROUND-COLOR: #0000ff"
align=center><B><FONT 
color=#ffffff size=5><BR>REGISTRATION FORM<BR><BR></FONT></B></P>
  <PRE><B>
<FONT color=#ff0000>REQUIRED QUESTIONS:</FONT></B>
   <BR>
   1. What is your student id number?&nbsp;<INPUT tabIndex=2
maxLength=46 size=46 name=student_id><BR>
   2. What is your name?<BR>
   First name:<input type="Text" name="firstname"><br>
 Last name:<input type="Text" name="lastname"><br>
 Address: <input type="Text" name="address" size="60"><BR>
</PRE>
<UL>
  <LI>
      <P style="BACKGROUND-COLOR: #ffffff"><font color="#FF3300">Please
click 
        the Submit Button only once</font> </P>
    <LI> 
      <P style="BACKGROUND-COLOR: #ffffff"><font color="#FF3300">Then
wait for 
        your confirmation screen</font> </P>
    <LI> 
      <P style="BACKGROUND-COLOR: #ffffff"><font color="#FF3300">Save
the confirmation 
        screen because it has information you will need</font> </P>
    </LI></UL>
<P style="BACKGROUND-COLOR: #ffffff"><INPUT type=submit value="Submit
Registration">&nbsp;</P>
<P style="BACKGROUND-COLOR: #ff0000" align=center>End of Form-Thank 
You!</P></FORM>
<HR>
<H5 style="BACKGROUND-COLOR: #ffffff"> </H5>
<?php
} // end if
?>
</BODY></HTML>



Reply via email to