English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

$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

2 answers

Why not just use auto increment for your PatientID field in the MySQL database?

2006-12-20 03:45:10 · answer #1 · answered by LorettoBoy 4 · 0 0

The one thing that pops into my mind, is the lack of a semi-colon (;) at the end of what would be Line 16 $results=mysql_query($sql) <--Semi-Colon needed $results=mysql_query($sql); First thing I always do when I get an error on x line is to look at the preceding line. So since your error was a line 17, look at line 16. Doesn't always mean that the error is on the preceding line, but its a good starting place for me. ----- They always say two heads are better than one. The semi colon removes the error, as you've seen, but the answer the second person gave should insert the data into the database (adding ", $con) $results=mysql_query($sql, $con); The mysql_query, the way you had it coded, wasn't telling PHP which database to connect to ($con).

2016-05-23 00:09:16 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers