Jump to content


Photo

Automatic Clear boxes


  • Please log in to reply
1 reply to this topic

#1 cnagra

cnagra
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 18 April 2006 - 08:59 PM

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


?>


#2 devofash

devofash
  • Members
  • PipPipPip
  • Advanced Member
  • 81 posts

Posted 18 April 2006 - 10:05 PM

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)

<INPUT TYPE="text" NAME="text_field" VALUE="somevalue" onClick="this.value=''">





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users