PHP MYSQL FORM TO UPDATE TABLE WON'T WORK PLEASE HELP?

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>

<input type="submit" value="Save" name="submit"/>
</form>

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

mysql_select_db("database", $con);

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

mysql_close($con);

?>

</form>
I'm doing the update because there will be default information.

I just started php a cpl of months ago and this is my first hand written project. Any examples would help.
 
Use INSERT INTO for the first time you are inserting a record. UPDATE should be used to edit content that already exsists in the table.
 
I think when you are hitting enter you are calling the page again without any parameters passes so $about is set to nothing and therefore our query updates it to nothing.

I would put some check in there to make sure that $about is set before doing the the update.
 
Back
Top