Jump to content

simple form to update database


joemorris86

Recommended Posts

edit: I got it working now, ive updated the code just incase it helps anyone down the lineHi guys, I have been searching the internet for about 5 hours now trying to find a tutorial I can understand to update some information in my database.I have half gotten a few working, and I'm fairly comfortable with forms now. Its just the update.php page that I just cant seem to get right.Would anybody be able to show me the simplest code to just update the row 'age' from my database called 'people' where the id is '1'Im hoping If i can understand the basics I can build up to what i want it to finally do.Thanks for any helpThis is one of the codes I have tried to get working.

// Connect to server and select database.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// Get values from form$current_hp = $_POST['current_hp'];$current_mp = $_POST['current_mp'];$current_ap = $_POST['current_ap'];// Insert data into mysql$sql = "update game_char set current_hp='".$_POST['current_hp']."' ,current_mp='".$current_mp."',current_ap='".$_POST['current_hp']."' where id='1'";$result=mysql_query($sql);// if successfully insert data into database, displays message "Successful".if($result){echo "Successful";echo "<BR>";echo "<a href='/testdir/cloud/?x=navigation&y=dbtest'>Back to main page</a>";}else {echo "ERROR";}// close connectionmysql_close();?>

This echos the error when I submit my form and I cant see why, any ideas?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...