tubaplaya76
07-21-2006, 07:00 PM
Hey, I wrote this [seemingly] easy script to act as a "last updated" script, with the pressing of a button. It does what I want perfectly, however, it oftentimes adds a random entry with an ID, but no text. Also, this usually happens when I click on the button after closing out of the Browser and then reopening it. Any Suggestions?
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" value="<?php echo date('F jS Y h:i:s A'); ?>" name="info">
<input type="submit" name="submit" value="Last Updated Update Button">
</form>
</body>
</html>
<?php
// set database server access variables:
// this is correct
// get form input
$de = mysql_escape_string($_POST['info']);
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query insert
$query = "INSERT INTO up (text) VALUES ('$de')";
// execute query insert
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// print message with ID of inserted record
if (isset($_POST['submit'])) {
echo "Date successfully inserted with id ".mysql_insert_id();
}
//free result set memory
@mysql_free_result($result);
// close connection
mysql_close($connection);
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" value="<?php echo date('F jS Y h:i:s A'); ?>" name="info">
<input type="submit" name="submit" value="Last Updated Update Button">
</form>
</body>
</html>
<?php
// set database server access variables:
// this is correct
// get form input
$de = mysql_escape_string($_POST['info']);
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query insert
$query = "INSERT INTO up (text) VALUES ('$de')";
// execute query insert
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// print message with ID of inserted record
if (isset($_POST['submit'])) {
echo "Date successfully inserted with id ".mysql_insert_id();
}
//free result set memory
@mysql_free_result($result);
// close connection
mysql_close($connection);
?>