Log in

View Full Version : rewriting existing information in mysql



auriaks
10-21-2009, 03:22 PM
Hi, I have sql table named: THEME, and line in it, named: Thh, were i saved Thh variable from form. Can someone explain what Form script do i need to rewrite information in Thh. For example: Thh was badboy, but when i went to my webpage i want to change it to goodboy :D what script i have to use? MANY THANKS :)

traq
10-22-2009, 02:25 AM
form.html


...
<form action="processform.php" method="post">
<input type="text" name="Thh">
<!--OR THIS INSTEAD (comment out above <input> and uncomment this to use)
<select name="Thh">
<option value="badboy">Bad Boy</option>
<option value="goodboy">Good Boy</option>
</select>
-->
<!--then submit the form-->
<input type="submit" value="submit">
</form>
...

processform.php


if(isset($_POST['Thh'])){
$Thh = $_POST['Thh'];
$Thh = addslashes($Thh);
$id = ''; // id of the row you want to update
// IMPORTANT! if you don't specify a row, ALL ROWS will be updated!
$SQL = "UPDATE theme SET Thh = '$Thh' WHERE id ='$id' ";
// This assumes you've already connected to your DB
if(mysql_query($SQL)){ echo 'Success!'; }else{ echo 'Failure.'; }

// if you used the <select> on the form you can easily validate the user's input
// (comment out the lines above and uncomment these):
// $OKvalues = array('badboy','goodboy');
// if(in_array($_POST['Thh'], $OKvalues)){
// $Thh = $_POST['Thh'];
// $id = ''; // id of the row you want to update
// $SQL = "UPDATE theme SET Thh = '$Thh' WHERE id ='$id' ";
// if(mysql_query($SQL)){ echo 'Success!'; }else{ echo 'Failure.'; }
// }
}