cnagra Posted April 18, 2006 Share Posted April 18, 2006 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?thanksphp code : <?phpmysql_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?> Quote Link to comment Share on other sites More sharing options...
devofash Posted April 18, 2006 Share Posted April 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.