I want to enter the data back once a user click submit and they haven't fill all data in yet.
How would I do that?
Also, if all fields are enter. It will go to another page instead staying on the same page.
I use:
<form name="create_form" method="POST" action="<?php echo $PHP_SELF; ?>">
This will add data to the database, but if I use like
<form name="create_form" method="POST" action="anotherPage.php">
This will not add data to the database.
Full code:
<?php include("config3.php"); ?>
<?php
if (isset($_POST['create_form'])) {
submitData();
}
function submitData() {
if (($_POST["NAME"] == "") or ($_POST["QUESTION"] == "")) {
echo "
<script type=\"text/javascript\">
alert(\"Please input all data.\")
</script>
";
}
mysql_select_db($dbNAME) or die($errCon . mysql_error());
mysql_query("INSERT INTO $tableNEW
(name,number,question)
VALUES('$NAME', '$NUMBER','$QUESTION') ")
or die($errCon . mysql_error());
} //end function
?>
<form name="create_form" method="POST" action="<?php echo $PHP_SELF; ?>">
<table>
<tr>
<td align="right">Name:</td>
<td><input name="NAME" size="25"></td>
</tr>
<tr>
<td align="right">Number:</td>
<td><select name="NUMBER">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
</select>
</td>
</tr>
<tr>
<td align="right">Question:</td>
<td>
<textarea name="QUESTION" rows="10" cols="40"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit" name="create_form">
<input type="reset" value="Reset" name="reset"></td>
</tr>
</table>
</form>