When I refresh the page or every time I go to it, a blank row is inserted into the database. This can not happen as I'm then printing out all the contents of the database. How can I stop it?
index.php:
[PHP]
<?php include "header.php "; ?>
<td valign="top"><b r />
<a href="addAnnoun ce.php">Click Here</a> to enter an announcement. <br /><br />
<img src="images/announceheader. gif" /><br />
<?php
//create variable names
$heading=$HTTP_ POST_VARS['heading'];
$announce=$HTTP _POST_VARS['announce'];
$date=$HTTP_POS T_VARS['date'];
$heading= trim($heading);
$announce= trim($announce) ;
$date= trim($date);
$heading= addslashes($hea ding);
$announce= addslashes($ann ounce);
$date= addslashes($dat e);
//connect to server
@ $db = mysql_pconnect( $hostname,$user name,$password) ;
if (!db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db ($databaseName) ;
// insert data into database
$insert = mysql_query("in sert into $table (heading, announce, date) values ('$heading', '$announce', '$date')")
or die("Could not insert data because ".mysql_error() );
?>
<?php
// Get all the data from the "example" table
$result = mysql_query("SE LECT * FROM $table")
or die(mysql_error ());
echo "<table border='0'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_arr ay( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><f ont class='heading' >";
echo $row['heading'];
echo "</font></td></tr><tr><td>";
echo $row['announce'];
echo "</td></tr><tr><td><fon t class='date'>";
echo $row['date'];
echo "</font></td></tr>";
echo "<tr><td> </td></tr>";
}
echo "</table>";
mysql_close();
?>
</td>
</tr>
</table>
</body>
</html>
[/PHP]
addAnnounce.php :
[PHP]<?php
include "header.php ";
?>
<td align=top>
<form action="index.p hp" method="post">H eading:<br /><input type="text" size="40" name="heading"/><br /><br />Announcement:< br />
<textarea name="announce" cols="50" rows="10"></textarea>
<br /><br />Date:<br /><input type="text" size="10" name="date"/><br /><br /><input type="submit" value="Post" /></form>
</td>
</table>
</body>
</html>[/PHP]
Thanks.
index.php:
[PHP]
<?php include "header.php "; ?>
<td valign="top"><b r />
<a href="addAnnoun ce.php">Click Here</a> to enter an announcement. <br /><br />
<img src="images/announceheader. gif" /><br />
<?php
//create variable names
$heading=$HTTP_ POST_VARS['heading'];
$announce=$HTTP _POST_VARS['announce'];
$date=$HTTP_POS T_VARS['date'];
$heading= trim($heading);
$announce= trim($announce) ;
$date= trim($date);
$heading= addslashes($hea ding);
$announce= addslashes($ann ounce);
$date= addslashes($dat e);
//connect to server
@ $db = mysql_pconnect( $hostname,$user name,$password) ;
if (!db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db ($databaseName) ;
// insert data into database
$insert = mysql_query("in sert into $table (heading, announce, date) values ('$heading', '$announce', '$date')")
or die("Could not insert data because ".mysql_error() );
?>
<?php
// Get all the data from the "example" table
$result = mysql_query("SE LECT * FROM $table")
or die(mysql_error ());
echo "<table border='0'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_arr ay( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><f ont class='heading' >";
echo $row['heading'];
echo "</font></td></tr><tr><td>";
echo $row['announce'];
echo "</td></tr><tr><td><fon t class='date'>";
echo $row['date'];
echo "</font></td></tr>";
echo "<tr><td> </td></tr>";
}
echo "</table>";
mysql_close();
?>
</td>
</tr>
</table>
</body>
</html>
[/PHP]
addAnnounce.php :
[PHP]<?php
include "header.php ";
?>
<td align=top>
<form action="index.p hp" method="post">H eading:<br /><input type="text" size="40" name="heading"/><br /><br />Announcement:< br />
<textarea name="announce" cols="50" rows="10"></textarea>
<br /><br />Date:<br /><input type="text" size="10" name="date"/><br /><br /><input type="submit" value="Post" /></form>
</td>
</table>
</body>
</html>[/PHP]
Thanks.
Comment