HI, i have written a bookmarking page that lets me add urls to database. as i have placed both database results and new url button code in same page. i have a bit conflict. whenever i refresh the page, dot entry goes in database and table gets populated which is flaw i guess. i am looking for a way to fix this.
here is my code
<html>
<style type="text/css">
table.db-table { border-right:1px solid #ccc; border-bottom:1px solid #ccc; }
table.db-table th { background:#eee; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc; }
table.db-table td { padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc; }
</style>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("delicious") or die(mysql_error());
$data = mysql_query("SELECT * FROM stacks") or die(mysql_error());
if(mysql_num_rows($data)) {
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo '<tr><th>No</th><th>Name</th><th>URL</th></tr>';
while($row2 = mysql_fetch_row($data))
{
echo '<tr>';
foreach($row2 as $key=>$value)
{
echo '<td>',$value,'</td>';
}
echo '</tr>';
}
echo '</table><br />';
}
$Name=$_POST["Name"];
$URL=$_POST["URL"];
$query="INSERT INTO stacks (No,Name,URL) values ('NULL','.$Name','.$URL')";
mysql_query($query) or die('Error updating database');
?>
<form method="post" action="php_code.php">
<b>Name : </b>
<input type="text" name="Name" size="30" /><br/>
<b>URL : </b>
<input type="text" name="URL" size="30" /><br/>
<input type="submit" value="Add another URL"/>
</form>
</html>