php mysql about me form clears database table if revisited?

jf795

New member
The information will save into the database. I can refresh and it will remain saved. In my browser, after saving the information, if I click go or click on the url and hit enter, the form clears and the tables clear in mysql. How can I prevent this and what am I doing wrong?

<?php
$about = $_POST["about"];
?>
</head>

<body>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<form><textarea name="about" input type="text" cols="30" rows="10">
<? echo stripslashes($about);
$about=nl2br($about); ?>
</textarea><br />
<input type="submit" value="Save" name="submit"/>
</form>

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

mysql_query("UPDATE info SET about = '$about'");

mysql_close($con);

?>

</form>
Ok I made the changes and still the same result.


if ($_POST['about']) {


mysql_select_db("db", $con);

mysql_query("INSERT INTO info WHERE about = '$about'");
}
 
You must update the table only when the form is submitted.
Use:
if ($_POST['about']) {
//update db
}
You also probably want each submit to generate insert of row instead of update.
 
Back
Top