Jump to content

php and mysql update


Porkie

Recommended Posts

i'am trying to work out how to update a field in my database, basically when the user clicks update, the data they have typed in will be updated on the database. Where do i put the update sql query, and how would i go about it.

 

<form action="" method="get" name="comp1england">
  <label>
  <textarea name="englandsong" cols="80" rows="30" id="englandsong"></textarea>
  </label>
    <input name="Save" type="submit" id="Save" value="Save">
    <input name="Update" type="submit" id="Update" value="Update">
    <input name="Finalise" type="submit" id="Finalise" value="Finalise">
    <input name="Reset" type="reset" id="Reset" value="Reset">
</form>
</html>

 

cheers in advance

Link to comment
https://forums.phpfreaks.com/topic/174197-php-and-mysql-update/
Share on other sites

Hi porkie,

 

You would need to do something like:

 

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$englandsong = addslashes($_POST['englandsong']);


		$sql = mysql_query("UPDATE TABLE_NAME SET 

		englandsong = '".$englandsong."' ");

		 if ($sql)
		 {
			 echo "Updated successfully";
		 }
		 else
		 {
		 	echo "There was an error updating the database";

		 }
}
?>
<form action="" method="POST" name="comp1england">
  <label>
  <textarea name="englandsong" cols="80" rows="30" id="englandsong"></textarea>
  </label>
<input name="Update" type="submit" id="Update" value="Update">
<input name="Reset" type="reset" id="Reset" value="Reset">

</form>

 

But you cannot have multiple submit buttons on one form as you have with your orginal HTML code.

 

Hope this helps.

Link to comment
https://forums.phpfreaks.com/topic/174197-php-and-mysql-update/#findComment-918316
Share on other sites

Archived

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

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