Jump to content

Updating fields


weetabix

Recommended Posts

Ok, I created an HTML table for the user to enter some data and then under my HTML I started writing the PHP for the data to be updated. Only tried it in one field so far but it won't work.

 

Here's some of my HTML code:

<form action="updateStaff.php" method="post">
<p><table border='0' width='77%'>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">
	<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>

 

and my PHP code:

<?PHP
	$username = $_POST['updateuser'];
	$query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";
	mysql_query($query);
	echo 'Data Saved!';
?>

 

I'm using a function to connect to my database which is correct and working (tried it with other files) so I can't really see the problem.

 

thanks

Link to comment
Share on other sites

got it, i was sending it to the wrong file

 

dumb me.

 

however, as the entry is given to it to be updated then the file updateStaff is called.

 

and then, there is a check if the staffid is sent to it.

 

How can I get it to send the staffid as well with the updated field?

 

Or is it easier to display a message box somehow saying: field updated instead of refreshing the page?

Link to comment
Share on other sites

I think I didnt explain properly.

 

I have a page where the user enters the ID of the staff. Then, if the number is correct they are forwarded to another page where they can change certain fields from the staff table. Each field has an "update" button next to it, so that once they enter the data they can click on update and change it.

 

What I'm trying to do, is to get a message saying "Data Updated" once they click the button and the update is done.

 

However, if I try to do that by calling the same page again [which is what i'm doing now] the first check for the staff id is applied. This is practically empty at this stage and the change in the fields doesnt work.

Link to comment
Share on other sites

You mean change to GET instead of POST?

I tried but it still wont work :(

 

Anyway here's the whole thing

 

<HTML>
<head>
<title> abcBooks: Staff Update </title>
</head>
<body>

<p align="center"><b>Staff Information Update</b></p>

<?php

	if(!isset($_GET['staffid'])){
	   echo "Staff ID was not provided!";
	   die();
	}

	$testid = $_GET['staffid'];


//Database connection works but didnt enter it

?>

<form action="staffUpdate.php" method="get">
<?php

echo "<p> Staff ID: <input type = 'Text' name='username' value='$testid' readonly ></P>";
?>

<p><table border='0' width='77%'>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">
	<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Password:</td>
	<td width="30%"><input type = "Text" name="password"></td>
	<td width="8%"><input type= "submit" name="updatePass" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Last Name: </td>
	<td width="100%"><input type = "Text" name="surname"></td>
	<td width="15%"><input type= "submit" name="updateSurname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Telephone:</td>
	<td width="30%"><input type = "Text" name="telephone"></td>
	<td width="8%"><input type= "submit" name="updatePhone" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Address:</td>
	<td width="100%"><input type = "Text" name="address"></td>
	<td width="15%"><input type= "submit" name="updateAddress" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Email:</td>
	<td width="30%"><input type = "Text" name="email"></td>
	<td width="8%"><input type= "submit" name="updateEmail" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Postcode:</td>
	<td width="100%"><input type = "Text" name="postcode"></td>
	<td width="15%"><input type= "submit" name="updatePostcode" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
</table></p>
</form>


<?PHP
	$username = $_GET['updateuser'];
	$query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$firstname = $_POST['updateFirstname'];
	$query = "UPDATE Staff SET first_name = '$firstname' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$password = $_POST['updatePass'];
	$query = "UPDATE Staff SET password = '$password' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$surname = $_POST['updateSurname'];
	$query = "UPDATE Staff SET first_name = '$surname' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$phone = $_POST['updatePhone'];
	$query = "UPDATE Staff SET telephone_no = '$phone' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$address = $_POST['updateAddress'];
	$query = "UPDATE Staff SET address = '$address' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$email = $_POST['updateEmail'];
	$query = "UPDATE Staff SET address = '$email' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$postcode = $_POST['updatePostcode'];
	$query = "UPDATE Staff SET address = '$postcode' WHERE staff_id = '$staffid'";
	mysql_query($query);

?>

</body>
</html>

Link to comment
Share on other sites

try this

 

<HTML>
<head>
<title> abcBooks: Staff Update </title>
</head>
<body>

<p align="center"><b>Staff Information Update</b></p>

<?php
####################<<<<<<<<<--------------DATABASE CONNECTION HERE

	$staff = mysql_real_escape_string($_GET['staffID']);
	$val = mysql_query("SELECT * FROM Staff WHERE staff_id = '$staff'");

	if(($staff == "")||(!isset($staff)){

	echo'Please provide us with a valid Staff ID';

	}
	elseif(mysql_num_rows($val)==0){

	echo'Please provide us with a valid Staff ID';

	}


?>

<form action="staffUpdate.php?staffID=<?php echo $_GET['staffID']; ?>" method="get">
<?php

echo "<p> Staff ID: <input type = 'Text' name='username' value='".$staff."' readonly ></P>";
?>

<p><table border='0' width='77%'>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">
	<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Password:</td>
	<td width="30%"><input type = "Text" name="password"></td>
	<td width="8%"><input type= "submit" name="updatePass" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Last Name: </td>
	<td width="100%"><input type = "Text" name="surname"></td>
	<td width="15%"><input type= "submit" name="updateSurname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Telephone:</td>
	<td width="30%"><input type = "Text" name="telephone"></td>
	<td width="8%"><input type= "submit" name="updatePhone" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Address:</td>
	<td width="100%"><input type = "Text" name="address"></td>
	<td width="15%"><input type= "submit" name="updateAddress" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Email:</td>
	<td width="30%"><input type = "Text" name="email"></td>
	<td width="8%"><input type= "submit" name="updateEmail" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Postcode:</td>
	<td width="100%"><input type = "Text" name="postcode"></td>
	<td width="15%"><input type= "submit" name="updatePostcode" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
</table></p>
</form>


<?PHP

$staffid = $_GET['staffID'];
	$username = $_GET['updateuser'];
	$query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$firstname = $_POST['updateFirstname'];
	$query = "UPDATE Staff SET first_name = '$firstname' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$password = $_POST['updatePass'];
	$query = "UPDATE Staff SET password = '$password' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$surname = $_POST['updateSurname'];
	$query = "UPDATE Staff SET first_name = '$surname' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$phone = $_POST['updatePhone'];
	$query = "UPDATE Staff SET telephone_no = '$phone' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$address = $_POST['updateAddress'];
	$query = "UPDATE Staff SET address = '$address' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$email = $_POST['updateEmail'];
	$query = "UPDATE Staff SET address = '$email' WHERE staff_id = '$staffid'";
	mysql_query($query);

	$postcode = $_POST['updatePostcode'];
	$query = "UPDATE Staff SET address = '$postcode' WHERE staff_id = '$staffid'";
	mysql_query($query);

?>

</body>
</html>

Link to comment
Share on other sites

Alright, this should work fine...

 

<?php
####################<<<<<<<<<--------------DATABASE CONNECTION HERE

$mode = $_GET['mode']; // Get the mode
$staffid = mysql_real_escape_string($_POST['staff_id']); // the staff id posted by the user
$val = mysql_query("SELECT * FROM Staff WHERE staff_id = '$staff'");

if((isset($mode))&&($mode=="update")){

    if(mysql_num_rows($val)==0){

	die('Please provide us with a valid Staff ID');

	}
	else(

             $username = $_POST['username'];
	$query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$firstname = $_POST['updateFirstname'];
	$query = "UPDATE Staff SET first_name = '$firstname' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$password = $_POST['updatePass'];
	$query = "UPDATE Staff SET password = '$password' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$surname = $_POST['updateSurname'];
	$query = "UPDATE Staff SET first_name = '$surname' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$phone = $_POST['updatePhone'];
	$query = "UPDATE Staff SET telephone_no = '$phone' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$address = $_POST['updateAddress'];
	$query = "UPDATE Staff SET address = '$address' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$email = $_POST['updateEmail'];
	$query = "UPDATE Staff SET address = '$email' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$postcode = $_POST['updatePostcode'];
	$query = "UPDATE Staff SET address = '$postcode' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		
  echo 'Update Completed';

	}

  }
  

?>
<HTML>
<head>
<title> abcBooks: Staff Update </title>
</head>
<body>

<p align="center"><b>Staff Information Update</b></p>



<form action="?mode=update" method="POST">
<?php

echo "<p> Staff ID: <input type = 'Text' name='staff_id'></P>";
?>

<p><table border='0' width='77%'>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">
	<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Password:</td>
	<td width="30%"><input type = "Text" name="password"></td>
	<td width="8%"><input type= "submit" name="updatePass" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Last Name: </td>
	<td width="100%"><input type = "Text" name="surname"></td>
	<td width="15%"><input type= "submit" name="updateSurname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Telephone:</td>
	<td width="30%"><input type = "Text" name="telephone"></td>
	<td width="8%"><input type= "submit" name="updatePhone" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Address:</td>
	<td width="100%"><input type = "Text" name="address"></td>
	<td width="15%"><input type= "submit" name="updateAddress" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Email:</td>
	<td width="30%"><input type = "Text" name="email"></td>
	<td width="8%"><input type= "submit" name="updateEmail" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Postcode:</td>
	<td width="100%"><input type = "Text" name="postcode"></td>
	<td width="15%"><input type= "submit" name="updatePostcode" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
</table></p>
</form>



</body>
</html>

Link to comment
Share on other sites

keeps returning 

 

Please provide us with a valid Staff ID

 

apparently when the query is executed it calls back the same page and that needs the staffid to work. and without passing it to it, it doesnt work right ?

 

something goes wrong when passing the id to the page.

Link to comment
Share on other sites

Try now

 

<?php
####################<<<<<<<<<--------------DATABASE CONNECTION HERE

$mode = $_GET['mode']; // Get the mode
$staffid = mysql_real_escape_string($_POST['staff_id']); // the staff id posted by the user
$val = mysql_fetch_array(mysql_query("SELECT * FROM Staff WHERE staff_id = '$staff'"));

if($mode=="update"){

    if($val['staff_id']==$staffid){


	$query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

	$firstname = $_POST['updateFirstname'];

	$query2 = "UPDATE Staff SET first_name = '$firstname' WHERE staff_id = '$staffid'";
	mysql_query($query2) or die("Sorry, but there was a problem with the update process");		

	$password = $_POST['updatePass'];
	$query3 = "UPDATE Staff SET password = '$password' WHERE staff_id = '$staffid'";
	mysql_query($query3) or die("Sorry, but there was a problem with the update process");		

	$surname = $_POST['updateSurname'];
	$query4 = "UPDATE Staff SET first_name = '$surname' WHERE staff_id = '$staffid'";
	mysql_query($query4) or die("Sorry, but there was a problem with the update process");		

	$phone = $_POST['updatePhone'];
	$query5 = "UPDATE Staff SET telephone_no = '$phone' WHERE staff_id = '$staffid'";
	mysql_query($query5) or die("Sorry, but there was a problem with the update process");		

	$address = $_POST['updateAddress'];
	$query6 = "UPDATE Staff SET address = '$address' WHERE staff_id = '$staffid'";
	mysql_query($query6) or die("Sorry, but there was a problem with the update process");		

	$email = $_POST['updateEmail'];
	$query7 = "UPDATE Staff SET address = '$email' WHERE staff_id = '$staffid'";
	mysql_query($query7) or die("Sorry, but there was a problem with the update process");		

	$postcode = $_POST['updatePostcode'];
	$query8 = "UPDATE Staff SET address = '$postcode' WHERE staff_id = '$staffid'";
	mysql_query($query8) or die("Sorry, but there was a problem with the update process");		

    echo 'Update Completed';

	}
	else
	{

	echo 'Invalid Staff ID';

	}

  }
  

?>
<HTML>
<head>
<title> abcBooks: Staff Update </title>
</head>
<body>

<p align="center"><b>Staff Information Update</b></p>



<form action="?mode=update" method="POST">
<p><table border='0' width='77%'>
<tr>
  <td>Staff ID:</td>
  <td><input type = 'Text' name='staff_id'></td>
  <td colspan="3"> </td>
  <td> </td>
    </tr>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">
	<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Password:</td>
	<td width="30%"><input type = "Text" name="password"></td>
	<td width="8%"><input type= "submit" name="updatePass" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Last Name: </td>
	<td width="100%"><input type = "Text" name="surname"></td>
	<td width="15%"><input type= "submit" name="updateSurname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Telephone:</td>
	<td width="30%"><input type = "Text" name="telephone"></td>
	<td width="8%"><input type= "submit" name="updatePhone" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Address:</td>
	<td width="100%"><input type = "Text" name="address"></td>
	<td width="15%"><input type= "submit" name="updateAddress" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Email:</td>
	<td width="30%"><input type = "Text" name="email"></td>
	<td width="8%"><input type= "submit" name="updateEmail" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Postcode:</td>
	<td width="100%"><input type = "Text" name="postcode"></td>
	<td width="15%"><input type= "submit" name="updatePostcode" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
</table>
</p>
</form>



</body>
</html>

 

Why do you have so many UPDATE buttons? It wont do them individually, not the way your script is setup.

Link to comment
Share on other sites

So all the fields need to be changed to be updated ?

 

Well lets say you have your first field called USERNAME, and the update button for it is called "updateuser", then you would have to do

 

<?php
####################<<<<<<<<<--------------DATABASE CONNECTION HERE

$mode = $_GET['mode']; // Get the mode
$staffid = mysql_real_escape_string($_POST['staff_id']); // the staff id posted by the user
$val = mysql_fetch_array(mysql_query("SELECT * FROM Staff WHERE staff_id = '$staff'"));

if($mode=="update"){

    if($val['staff_id']==$staffid){

           // BUTTONS
	   $updateuser = $_POST['updateuser'];

    if(isset($updateuser)){
    $username = $_POST['username'];
	$query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";
	mysql_query($query) or die("Sorry, but there was a problem with the update process");		

		echo 'User column has been update <br>';

		}

	$firstname = $_POST['updateFirstname'];
	$query2 = "UPDATE Staff SET first_name = '$firstname' WHERE staff_id = '$staffid'";
	mysql_query($query2) or die("Sorry, but there was a problem with the update process");		

	$password = $_POST['updatePass'];
	$query3 = "UPDATE Staff SET password = '$password' WHERE staff_id = '$staffid'";
	mysql_query($query3) or die("Sorry, but there was a problem with the update process");		

	$surname = $_POST['updateSurname'];
	$query4 = "UPDATE Staff SET first_name = '$surname' WHERE staff_id = '$staffid'";
	mysql_query($query4) or die("Sorry, but there was a problem with the update process");		

	$phone = $_POST['updatePhone'];
	$query5 = "UPDATE Staff SET telephone_no = '$phone' WHERE staff_id = '$staffid'";
	mysql_query($query5) or die("Sorry, but there was a problem with the update process");		

	$address = $_POST['updateAddress'];
	$query6 = "UPDATE Staff SET address = '$address' WHERE staff_id = '$staffid'";
	mysql_query($query6) or die("Sorry, but there was a problem with the update process");		

	$email = $_POST['updateEmail'];
	$query7 = "UPDATE Staff SET address = '$email' WHERE staff_id = '$staffid'";
	mysql_query($query7) or die("Sorry, but there was a problem with the update process");		

	$postcode = $_POST['updatePostcode'];
	$query8 = "UPDATE Staff SET address = '$postcode' WHERE staff_id = '$staffid'";
	mysql_query($query8) or die("Sorry, but there was a problem with the update process");		

    echo 'Update Completed';

	}
	else
	{

	echo 'Invalid Staff ID';

	}

  }
  

?>
<HTML>
<head>
<title> abcBooks: Staff Update </title>
</head>
<body>

<p align="center"><b>Staff Information Update</b></p>



<form action="?mode=update" method="post">
<p><table border='0' width='77%'>
<tr>
  <td>Staff ID:</td>
  <td><input type = 'Text' name='staff_id'></td>
  <td colspan="3"> </td>
  <td> </td>
    </tr>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">
	<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Password:</td>
	<td width="30%"><input type = "Text" name="password"></td>
	<td width="8%"><input type= "submit" name="updatePass" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Last Name: </td>
	<td width="100%"><input type = "Text" name="surname"></td>
	<td width="15%"><input type= "submit" name="updateSurname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Telephone:</td>
	<td width="30%"><input type = "Text" name="telephone"></td>
	<td width="8%"><input type= "submit" name="updatePhone" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Address:</td>
	<td width="100%"><input type = "Text" name="address"></td>
	<td width="15%"><input type= "submit" name="updateAddress" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Email:</td>
	<td width="30%"><input type = "Text" name="email"></td>
	<td width="8%"><input type= "submit" name="updateEmail" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Postcode:</td>
	<td width="100%"><input type = "Text" name="postcode"></td>
	<td width="15%"><input type= "submit" name="updatePostcode" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
</table>
</p>
</form>



</body>
</html>

 

Try to update the USERNAME column, and it will do it individually. Then you repeat the if process for the rest of the coloumns you want to update.

 

I can do it for you, but did this work or not?

Link to comment
Share on other sites

Alright, try this

 

<?php
####################<<<<<<<<<--------------DATABASE CONNECTION HERE

$mode = $_GET['mode']; // Get the mode
$staffid = mysql_real_escape_string($_POST['staff_id']); // the staff id posted by the user
$val = mysql_fetch_array(mysql_query("SELECT * FROM Staff WHERE staff_id = '$staff'"));

if($mode=="update"){

    if($val['staff_id']==$staffid){

           // BUTTONS
	   $updateuser = $_POST['updateuser'];
	   $updatePass = $_POST['updatePass'];
	   $updatePhone = $_POST['updatePhone'];
	   $updateEmail = $_POST['updateEmail'];
	   $updateFirstname = $_POST['updateFirstname'];
	   $updateSurname = $_POST['updateSurname'];
	   $updateAddresse = $_POST['updateAddress'];
	   $updatePostcode = $_POST['updatePostcode'];

    if(isset($updateuser)){

  $username = $_POST['username'];
  $query = "UPDATE Staff SET username = '$username' WHERE staff_id = '$staffid'";

  mysql_query($query) or die("Sorry, but there was a problem with the update process");		

 echo 'Updated Username <br>';

       }

	if(isset($updateFirstname)){
	$firstname = $_POST['firstname'];
	$query2 = "UPDATE Staff SET first_name = '$firstname' WHERE staff_id = '$staffid'";
	mysql_query($query2) or die("Sorry, but there was a problem with the update process");		

	echo 'Updated Firstname <br>';

	}

	if(isset($updatePass)){

	$password = $_POST['password'];
	$query3 = "UPDATE Staff SET password = '$password' WHERE staff_id = '$staffid'";
	mysql_query($query3) or die("Sorry, but there was a problem with the update process");

     echo 'Updated password <br>';

	}
	if(isset($updateSurname)){

	$surname = $_POST['lastname'];
	$query4 = "UPDATE Staff SET first_name = '$surname' WHERE staff_id = '$staffid'";
	mysql_query($query4) or die("Sorry, but there was a problem with the update process");	

	echo 'Updated Lastname <br>';

	}
	if(isset($updatePhone)){	

	$phone = $_POST['telephone'];
	$query5 = "UPDATE Staff SET telephone_no = '$phone' WHERE staff_id = '$staffid'";
	mysql_query($query5) or die("Sorry, but there was a problem with the update process");	

	echo 'Update Phone number <br>';

	}
	if(isset($updateAddress)){	

	$address = $_POST['address'];
	$query6 = "UPDATE Staff SET address = '$address' WHERE staff_id = '$staffid'";
	mysql_query($query6) or die("Sorry, but there was a problem with the update process");

    echo 'Updated Address <br>';


	}
	if(isset($updateEmail)){		

	$email = $_POST['email'];
	$query7 = "UPDATE Staff SET address = '$email' WHERE staff_id = '$staffid'";
	mysql_query($query7) or die("Sorry, but there was a problem with the update process");

	echo 'Updated Email <br>';

	}
	if(isset($updatePostcode)){		

	$postcode = $_POST['postcode'];
	$query8 = "UPDATE Staff SET address = '$postcode' WHERE staff_id = '$staffid'";
	mysql_query($query8) or die("Sorry, but there was a problem with the update process");


	echo 'Updated Post Code';

    }
	}
	else
	{

	echo 'Invalid Staff ID';

	}

  }
  

?>
<HTML>
<head>
<title> abcBooks: Staff Update </title>
</head>
<body>

<p align="center"><b>Staff Information Update</b></p>



<form action="?mode=update" method="post">
<p><table border='0' width='77%'>
<tr>
  <td>Staff ID:</td>
  <td><input type = 'Text' name='staff_id'></td>
  <td colspan="3"> </td>
  <td> </td>
    </tr>
<tr>
	<td width="15%">Username:</td>
	<td width="30%"><input type = "Text" name="username"></td>
	<td width="8%">		<input type= "submit" name="updateuser" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">First Name:</td>
	<td width="100%"><input type = "Text" name="firstname" size="20"></td>
	<td width="15%"><input type= "submit" name="updateFirstname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Password:</td>
	<td width="30%"><input type = "Text" name="password"></td>
	<td width="8%"><input type= "submit" name="updatePass" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Last Name: </td>
	<td width="100%"><input type = "Text" name="surname"></td>
	<td width="15%"><input type= "submit" name="updateSurname" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Telephone:</td>
	<td width="30%"><input type = "Text" name="telephone"></td>
	<td width="8%"><input type= "submit" name="updatePhone" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Address:</td>
	<td width="100%"><input type = "Text" name="address"></td>
	<td width="15%"><input type= "submit" name="updateAddress" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
<tr>
	<td width="15%">Email:</td>
	<td width="30%"><input type = "Text" name="email"></td>
	<td width="8%"><input type= "submit" name="updateEmail" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
	<td width="19%">Postcode:</td>
	<td width="100%"><input type = "Text" name="postcode"></td>
	<td width="15%"><input type= "submit" name="updatePostcode" value= "Update" style="font-family: Tahoma; font-size: 10px; font-weight: bold"></td>
</tr>
</table>
</p>
</form>



</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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