This is PHP4 Code!


$result = @mysql_query("UPDATE some_table SET
					image_filename = '',
					something_else = 4
				WHERE indexer = $destid
				");

Example Update From An HTML Form


<!-------------------------------->
<!-------------------------------->
<!----- ADD TO DATABASE FORM ----->
<!-------------------------------->
<!-------------------------------->
<h2>Add To Database</h2>
<?php
if ( (isset($_POST['action'])) && ($_POST['action'] == "add_to_database") )
{
	$field1 = @mysql_real_escape_string($_POST['field1']);
	$field2 = @mysql_real_escape_string($_POST['field2']);
	
	//$field1 = trim($field1);
	//$field1 = ucwords($field1);
	
	$field_checkbox = 0;
	if(isset($_POST['field_checkbox']) && $_POST['field_checkbox'] == 'Yes')
		$field_checkbox = 1;
	

	$query1 = @mysql_query("SELECT * FROM my_table WHERE field1 = '$field1'");
	if (@mysql_num_rows($query1))
	{
		echo "VALUE ALREADY EXISTS!<br />";
	}
	else if ( ($field1 == "") || ($field2 == "") )
	{
		echo "INVALID FORM CONTENTS!<br />";
	}
	else
	{
		$result = @mysql_query("INSERT INTO my_table (
																field1,
																field2,
																field_checkbox
														) VALUES (
																'$field1',
																'$field2',
																$field_checkbox
														)");

	
		//Go to the new page
		header("Location: my_page.php");
		die();


		
	}
}
?>
<form id="AddRecordForm" action="myfile.php" method="POST">
  <input type="hidden" name="action" value="add_to_database" />
  <input type="hidden" name="some_id" value="<?php echo "$some_id";?>" />

  <label>Field 1:</label><br />
  <input type="text" name="field1" value="<?php echo "$field1";?>" size="80"  /><br />

  <label>Field 2:</label><br />
  <input type="text" name="field2" value="<?php echo "$field2";?>" size="80"  /><br />
  
  <label>FieldCheckbox:</label><br />
  <input type="checkbox" name="field_checkbox" value="Yes" /><br />

  <input type="submit" value="Store" id="Send" />
</form>

 

Maths Operations In Update Queries


	mysql_query("UPDATE some_table SET some_value_a = some_value_a + 1, some_value_b = some_value_b + 10  WHERE id = 1");

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.