bears38 0 Newbie Poster

Hi,

I am trying to update fields in my database through the use of textboxes in which when information is typed into them it will update the fields in the database.

In addition I would like to use a combo box to select the appropriate field to update when I select a user, the information is displayed in textboxes in which I am able to update.

<?php
// Make a MySQL connection
mysql_connect("localhost", "a9028294", "shadow38") or die(mysql_error());
mysql_select_db("a9028294_db1") or die(mysql_error());

$memID = $_POST['memID'];
$memFirstName = $_POST['memFirstName'];
$memLastName = $_POST['memLastName'];
$memEmail = $_POST['memEmail'];
$memTelephone = $_POST['memTelephone'];

// Insert a row of information into the table "members"

<?php
if ( isset($_POST['memFirstName']) && isset ($_POST['memID']) && isset ($_POST['memLastName']) && isset($_POST['memTelephone']) ){
$query = "UPDATE members SET memFirstName = '" . $_POST['memFirstname'] . "' WHERE memID = " . $_POST['memID'];
$query = "UPDATE members SET memLastName = '" . $_POST['memTelephone'] . "' WHERE memID = " . $_POST['memID'];
$query = "UPDATE members SET memTelephone = '" . $_POST['telephone'] . "' WHERE memID = " . $_POST['id'];


$result = mysql_query($query) or die(mysql_error());
	if (mysql_affected_rows() == 1){
		echo "<p>Update successful</p>\n";
	} elseif (mysql_affected_rows() == 0) {
		echo "<p>New value of age is the same as the old value</p>\n";
	} else {
		echo "<p>Update failed</p>\n";
	}
}
?>
<form action="<?php echo $PHP_SELFs ?>" method="POST">
<select name="id">
<?php
// Create drop-down list of members
$query = "SELECT * FROM members";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
	echo "<option value=\"" . $row['memID'] . "\"";
	if ( isset($id) && $id == $row['memID'] ){
		echo " selected=\"selected\"";
	}
	echo ">" . $row['memFirstName'] . " " . $row['memMiddleInitial'] . " " . $row['memLastName']  . "</option>\n";

}
?>

</select>
<label for="telephone">Telephone: </label><input type="text" id="telephone" name="telephone" />
<input type="submit" value="Submit" />
</form> 

// Get new member's ID
$memID = mysql_insert_id();
// Welcome message
echo "<p>Thank you for signing up to eByGum DVD Rentals. Your membership ID is $memID. Please quote it in any queries.</p>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Black and White</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/style.css" media="screen" />
</head>
<body>

<div id="wrap">

<div id="header">
<h1>eByGum DVD Rentals</h1>
</div>


<div class="left">
  <div class="articles">
    <p>&nbsp;</p>
  <p>Hello Welcome to the Sign Up Page of the website.</p>
  <p>&nbsp;</p>
  <p>To Sign Up please enter you details below:-</p>
<td colspan="3"><p>&nbsp;</p>
    <p><strong>Sign Up Form </strong></p></td>
</tr>

<form action="test3.php" method="post">
<p><strong>Firstname:</strong><br/>
<input type="text" name="memFirstName" /></p>
<p><strong>Lastname:</strong><br/>
<input type="text" name="memLastName" /></p>
<p><strong>Telephone:</strong><br/>
<input type="text" name="memTelephone" /></p>
<p><strong>Email:</strong><br/>
<input type="text" name="memEmail" /></p>
<p><input type="submit" name="submit" value="SignUp"/></p>
<p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  </form>
  </div>
  </div>
  
  <div class="right"> 
    
  <h2>Categories :</h2>
  <ul>
  <li><a href="http://homepages.shu.ac.uk/~a9028294/css/rentalindex.html">HomePage</a></li> 
  <li></li>
  </ul>
  </div>
  <div style="clear: both;"> </div>
  </div>
  
</body>
</html>

I would like it to work like this code does below and adapt it to update all the fields!! Not just one!!

<?php
// Make a MySQL connection
mysql_connect("localhost", "a9028294", "shadow38") or die(mysql_error());
mysql_select_db("a9028294_db1") or die(mysql_error());
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Admin Panel: Update Age</title>
</head>
<body>
<h1>Update Age</h1>

<?php
// Test for the variables $age and $id
// If present change the value of the age column for the selected member
// Indicate to user if the update was successful
if ( isset($_POST['telephone']) && isset ($_POST['id']) ){
$query = "UPDATE members SET memTelephone = '" . $_POST['telephone'] . "' WHERE memID = " . $_POST['id'];
$result = mysql_query($query) or die(mysql_error());
	if (mysql_affected_rows() == 1){
		echo "<p>Update successful</p>\n";
	} elseif (mysql_affected_rows() == 0) {
		echo "<p>New value of age is the same as the old value</p>\n";
	} else {
		echo "<p>Update failed</p>\n";
	}
}
?>
<form action="<?php echo $PHP_SELFs ?>" method="POST">
<select name="id">
<?php
// Create drop-down list of members
$query = "SELECT * FROM members";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
	echo "<option value=\"" . $row['memID'] . "\"";
	if ( isset($id) && $id == $row['memID'] ){
		echo " selected=\"selected\"";
	}
	echo ">" . $row['memFirstName'] . " " . $row['memMiddleInitial'] . " " . $row['memLastName']  . "</option>\n";

}
?>

</select>
<label for="telephone">Telephone: </label><input type="text" id="telephone" name="telephone" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Much Appreciated