[SOLVED]form appearing...help please...
Posted: Tue Jul 05, 2005 3:44 am
i have a code below:
when someone clicks the submit button, the form is still there...but the message confirms the data is written to the database...i just want to display the message confirming me that it is written to the database and the form will disappear...
please help...thanks in advance
Code: Select all
<?
if (isset($_POST['submit']))
{
$message = NULL;
if (empty($_POST['sample']))
{
$s = false;
$message .= 'no sample<br>';
}
else
{
$s = $_POST['sample'];
}
if (empty($_POST['type1']))
{
$type = false;
$message .= 'please select at least one<br>';
}
else
{
$type = $_POST['type1'];
}
if ($s && $type)
{
$query = "INSERT INTO sample(samplefield, anothersamplefield) VALUES ('$s','$type')";
$result = @mysql_query($query) or die(mysql_error());
if ($result)
{
echo 'written to db';
}
else
{
$message = 'no data written in the db';
exit();
}
mysql_close();
}
else
{
$message = 'please try again';
}
}
if (isset($message))
{
echo '<font color=red>'.$message.'</font>';
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><b/>sample
<input type="text" name="sample" value="<? if (isset($_POST['sample'])) echo $_POST['sample']; ?>" />
</p>
<p>
<select name="type1">
<option>choose a type</option>
<option>type 1</option>
<option>type 2</option>
<option>type 3</option>
</select>
</p>
<input type="submit" name="submit" value="submit" />
</form>please help...thanks in advance