Jump to content

Automatic Clear boxes


cnagra

Recommended Posts

hi.

i got a form that edits fields in my database, but once it edits the databas i want the boxes to be empty so i can enter new records to be edited. where do i put the code and what is the code?

thanks

php code :

<?php



mysql_pconnect('localhost');
mysql_select_db('dv8_database');



if ($submit) {

// here if no ID then adding else we're editing

if ($id) {

$sql = "UPDATE stock_control SET category='$category',model='$model',price='$price',stock_amount='$stock_amount' WHERE id=$id";

} else {

$sql = "INSERT INTO stock_control (model,category,price,stock_amount) VALUES ('$model','$category','$price','$stock_amount')";

}

// run SQL against the DB

$result = mysql_query($sql);

echo "Record Updated Successfully - Update Another ?";



printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["category"], $myrow["model"], $myrow["price"], $myrow["stock_amount"]);



}





?>
</div>
<form method="post" action="<?php echo $PHP_SELF?>">

<p align="center">
<?php



if ($id) {

// editing so select a record

$sql = "SELECT * FROM stock_control WHERE id=$id";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);

$id = $myrow["id"];

$category = $myrow["category"];

$model = $myrow["model"];

$price = $myrow["price"];

$stock_amount = $myrow["stock_amount"];

// print the id for editing



?>

<input type=hidden name="id" value="<?php echo $id ?>">

<?php

}



?></p>
<p align="center">
<input type="Text" name="id" value="<?php echo $id ?>">
</p>
<p align="center">
<input type="Text" name="category" value="<?php echo $category ?>">
</p>
<p align="center">
<input type="Text" name="model" value="<?php echo $model ?>">
</p>
<p align="center">
<input type="Text" name="price" value="<?php echo $price ?>">
</p>
<p align="center">
<input type="Text" name="stock_amount" value="<?php echo $stock_amount ?>">
</p>
<p align="right">
<input type="Submit" name="submit" value="Update Record">
<input name="reset" input type="reset" id="reset" value="Clear Form" />

</p>
</form>


<div align="center">
<?php


?>
Link to comment
https://forums.phpfreaks.com/topic/7776-automatic-clear-boxes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.