Forum Moderators: coopster
I need to create MySql based web form to store and display data at the same php-page. How can I manage that the form data will not be inserted again (as new record) into the DB in case of using the RELOAD-browser function?
I'm tired of trying it out :-<
Here is the code sample:
<html>
<head><title>impressions.php</title><head>
<body>
<?php
if ($valider) {
$db = mysql_connect("localhost", "user", "passwd");
mysql_select_db("db",$db);
$continu=1;
if ($nom == "")
{
print("Your name is needed!<br>");
$continu=0;
}
[...]
if ($continu == 1)
{
$date=date("Y-m-d");
$sql="INSERT INTO impression (name, email, impression, date, comments) VALUES ('$nom', '$email', '$impression', '$date', '$comments')";
mysql_query($sql, $db);
print("Thank you for giving me your impressions!<br>") ;
}
else
{
print("<a href=impressions.php>back</a>");
}
}
?>
[...]
<form method="post" action=<?php echo $PHP_SELF?>>
Your name : <input type="text" name="nom"><br>
Your e-mail : <input type="email" name="email"><br>
Did you <input type="radio" name="impression" value="aime"> lode
<input type="radio" name="impression" value="pasaime"> or not this Website.
<br>
Your comments : <textarea name="comments"></textarea>
<br><br>
<input type="submit" name="valider" value="Send">
</form>
[...]
</body>
</html>
Many thanx for the answers...
Welcome to WW. I think you would need to perform an sql SELECT befored the INSERT to make sure the record is not already in the database. Perhaps using the email address to check for uniqueness.
You could use the mysql_num_rows function to test how may rows the select query returned.
if(mysql_num_rows($queryResult) == 0){
// no results returned so that email isnt in so we can do the insert
}
Or you could use the SQL count() aggregate to do effectively the same thing.
Cheers
Lots of thx Robber...
I'm sitting here working on my diploma and sometimes I dont have a clue to do the basic things :-((
Bad for me, then I'm just like absolutely beginner on PHP and I have only something like 20-30 days to programm my web frontend for generating HTML/PDF reportfiles from <FORM> data.
SHOULD I BE IN PANIC?
Nooooo - because there is lot of great help out there ;-)!
Greeeeetz and stay tuned until the next question ;-)
redbanditos2005