problem with rows being added on refresh
Posted: Sun Jun 01, 2003 5:18 pm
Hello,
I've got a simple script that adds data to a table and then retrieves it on the same page. The problem is that when I refresh the page, the last row gets re-added to the table. Here's the script:
Would appreciate any help.
I've got a simple script that adds data to a table and then retrieves it on the same page. The problem is that when I refresh the page, the last row gets re-added to the table. Here's the script:
Code: Select all
<html>
<head><title>MySQL Test</title></head>
<body>
<form action="<? echo($PHP_SELF); ?>" method="post">
Author: <input type="text" name="author" size="10"><br>
Title: <input type="text" name="title" size="10"><br>
Art: <input type="text" name="art" size="30"><br>
<input type="submit" value="Submit!">
</form>
<?php
#--------------
# submit data
#--------------
if($title and $art)
{
#connect to mysql
$connection = @mysql_connect("localhost","user","pass")
or die("Sorry, unable to connect to MySQL");
#select db
$result = @mysql_select_db(asciiart,$connection)
or die("Sorry, unable to to get database. Maybe it's because you have big head");
#create query
$sql="insert into asciiart(author,title,art) values("$author", "$title", "$art")";
#execute query (result is bool)
$result=mysql_query($sql,$connection);
#success?
if(result){
echo("Record added successfully! $id $title $art");
}
else{
echo("Record was not added successfully!");
}
}
#--------------
# retrieve data
#--------------
#connect to mysql
$connection = @mysql_connect("localhost","cyberiapc","pass123")
or die("Sorry, unable to connect to MySQL");
#select db
$result = @mysql_select_db(asciiart,$connection)
or die("Sorry, unable to to get database.");
#create query
$sql="select author,title,art from asciiart";
#execute query (result is bool)
$result=mysql_query($sql,$connection);
#write the data
while($currentRow = mysql_fetch_array($result))
{
echo("<b><font size="1" face="verdana"");
echo("<br><br>Posted by " .$currentRowї"author"] ."<br>");
echo("Title " .$currentRowї"title"] ."<br>");
echo($currentRowї"art"] ."<br>");
echo("</font></b>");
}
?>
</body>
</html>