I have a table disease, which has the columns diid, diseasename and descrption, in a database called hcp.
I want to simply input from a HTML form; here is my code so far.
<html><head><title>Disease Inssert</title></head>
<body>
<form action="diseaselist.php" method="post">
Disease Name : <input type="text" name="txtDiseaseName" id="textbox" /><br />
Description : <input type="text" name="txtDiseaseDescription" id="textbox" /><br />
<input type="submit" name="btnDiseaseSubmit" id="button"/>
</form>
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("hcp");
if($_REQUEST['btnDiseaseSubmit'])
{
$queryDiseaseInsert="INSERT INTO disease (`diseasename` ,`description`) VALUES ('".$_REQUEST['txtDiseaseName']."', '".$_REQUEST['txtDiseaseDescription']."');";
$resultDI=mysql_query($queryDiseaseInsert) or die(mysql_error());
}
?>
After submitting, page is redirecting to the diseaselist.php, but the data is not saving in the database.
Can anyone see anything wrong with my query?
The form is submitting directly to the list
<form action="diseaselist.php" method="post">
.The code saving to the database is never executed.
You could create an intermediate page, let’s say
process.phpcontaining the code for adding to the database:Changes:
Now, in your current file, leave only the html code and update the
actionattribute to submit the form to theprocess.phpscript:Changes:
actionattribute toprocess.php