$con = mysql_connect("localhost","root","mysql");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$name=$_POST["name"];
$address=$_POST["address"];
$email=$_POST["email"];
$sql="INSERT INTO patient (PatientName,Address,Email) VALUES ('$name','$address','$email')";
$results=mysql_query($sql)
$selects=mysql_query("SELECT * FROM patient");
$row=mysql_fetch_array($selects);
$num=rand(1,4);
echo $num;
if($num==$row[0])
{
echo 'number exists';
$random=rand(1,4);
$mysql="UPDATE patient SET PatientID='$random'";
}
else
{
$set="INSERT INTO patient (PatientID) VALUE ('$num')";
}
?>
What i am doing is first inserting the patient details to database
Then i am selecting the complete table
Then i let the program create a random number. If random number created exists in the PatientID column let the program create another random number and save it .
2006-12-20
03:40:35
·
2 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design