In mysql database I’ve a student table with three fields namely CID, COURSETITLE and PID. The PID (PupilsID) field values have been displayed using drop down fields in the form.php page. Now I ‘ve succeeded in populating the database with new cid’s (CourseIDs) and CourseTitle, budt what I want to do to be able to validate data that is been inputed into the CID(CourseID) to see whether it exist in the table inorder to alert to the visitor of the existing data
Pls how can I enforce this type of validation
PHP Code:This is form.php
<?php
$db=mysql_connect("localhost","root","");
mysql_select_db("student",$db);
$result=mysql_query("select distinct PID from courses ORDER BY pid asc");
$name='';
while($rows=mysql_fetch_array($result))
{
extract($rows);
$name.="<option value=\"$PID\">$PID</option>";
}
?>
<form method="post" action="show.php" name="guestbook">
<table>
<tr><td>PupilsID<td><select name="pup">
<?php echo $name; ?>
</select>
<tr><td>CourseID<td><input type="text" name="textcid"><br/>
<tr><td>CourseTitle<td><input type="text" name="texttitle"><br/>
<tr><td><input type="submit" value="submit" name="btnsu">
<td><input type="reset" value="reset" name="btnre">
</form>PHP Code:This is the form handler
<?php
$db=mysql_connect("localhost","root","");
mysql_select_db("student",$db);
if(isset($_POST['btnsu']))
{
$db=mysql_connect("localhost","root","");
mysql_select_db("student",$db);
$COURSEID=$_POST['textcid'];
$COURSETITLE=$_POST['texttitle'];
$PID=$_POST['pup'];
$sql="INSERT INTO courses (CID,COURSETITLE,PID) VALUES ('$COURSEID','$COURSETITLE','$PID')";
mysql_query($sql);}
?>





Bookmarks