Jump to content

update a mysql table field


rthomson

Recommended Posts

Hi, when I submit a form I want to update a field in the "daterange" table.  In the form the id field (RID) from "daterange" is selected prior to submit.  Basically, I want to change the STATUS field to B (from A).

 

The structure of daterange table is as follows:

 

RID (key field)

DEND

MONTH

DATE

SITE

PRICE

STATUS

 

What is the easiest way to accomplish this?

 

Here is the code from the form (if it will help)...

<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT MONTH FROM daterange") 
or die(mysql_error());

  while($tier = mysql_fetch_array( $result )) 
  
	{
	   echo '<option value="'.$tier['MONTH'].'">'.$tier['MONTH'].'</option>';
	}

}

//**************************************
//     First selection results     //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}

function drop_1($drop_var)
{  
    include_once('db.php');
$result = mysql_query("SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' AND MONTH='$drop_var' ORDER BY DATE, SITE")
or die(mysql_error());

echo '<select name="RID">
      <option value=" " disabled="disabled" selected="selected">Choose a Reservation</option>';

	   while($drop_2 = mysql_fetch_array( $result )) 

		{
		 echo '<option value="'.$drop_2['RID'].'">'.$drop_2 ['DATE']. ', '.$drop_2 ['SITE']. ', '.$drop_2 ['PRICE'].'</option>';
		}

echo '</select> ';

echo "<br />";

echo "</select><p align=left><label><font size=\"2\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br />";

echo "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br />";

echo "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br />";

echo "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br />";

echo "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br />";

echo "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br />";

echo "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br />";

echo "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\"";
echo "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\"";
echo "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br />";

echo "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br />";
echo '<input type="submit" name="submit" value="Book Now!" /><br />';
echo '<input type="reset" name="submit" value="Reset" /><br />';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/237504-update-a-mysql-table-field/
Share on other sites

It looks from a quick glance at the form that your post script would get the value form $_POST['RID'].

 

$rid = (isset($_POST['RID']) ? (int)$_POST['RID'] : 0;

 

Then you simply have to do an update query.  You have done other queries, so I'm sure you can figure that code out. Just call mysql_query(). Updated do not return a result set, but you can check mysql_affected_rows if you want to verify that something actually got updated. 

 

UPDATE daterange SET status = 'B' WHERE RID = $rid

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.