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
Share on other sites

you can use javascript to do this .... its called onClick ... when a user clicks on the text box it empties it (or you can say fills it with an empty string)

[code]<INPUT TYPE="text" NAME="text_field" VALUE="somevalue" onClick="this.value=''">[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.