Jump to content

Updating fields


weetabix

Recommended Posts

Works just fine for me...

 

Once Again, try this one

 

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

$mode = $_GET['mode']; // Get the mode

if($mode=="update"){

  $staffid = mysql_real_escape_string($_POST['staff_id']); // the staff id posted by the user

  $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['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");		


	$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");




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



	$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");	





	$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");


	$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");



	$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 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">
<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

Oh, its working now

but I want it to remember the staff_id the user entered in the previous page.

I changed the code to

<?php
echo "<td><input type = 'Text' name='staff_id' value = '$staffid>'</td>"
?>

 

You can do that, but also, Your Query is ALL wrong lol.

 

you used the UPDATE Address like 4 times in the same query.

 

Also, what was the problem, the fact that there was no staff_id filled in or?

 

 

Also, you might want to use my other script where it updates things seperately

 

<?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 last_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 email = '$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 postcode = '$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 works, I installed the db you had, and tried it on my server. I had alot of errors lol, I am sorry, but this one will definately work.

 

edit: I added the StaffID to the staff id field, so it remembers which staff the user edited

 

 

<?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 = '$staffid'"));

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($_POST['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 last_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 email = '$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 postcode = '$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' value='".$_POST['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

ok, one more question

 

<td><input type = 'Text' name='staff_id' value='".$_POST['staff_id']."'></td>

 

doesnt this need the php brackets to work?

 

echo "" < you have two sets of double quotes

 

'". < Add a semi-quote, and a double quote to end the string, then we add the period to add a variable

 

'".$_POST['staff_id']."'

 

 

Thats it, if you understood, In other words, no you don't need any brackets at all.

Link to comment
Share on other sites

Oh god...

 

It works super fine.

 

Heres my code, I just tested it:

 

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

mysql_connect("localhost","root","");
mysql_select_db("5502");
$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 = '$staffid'"));

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($_POST['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 last_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 email = '$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 postcode = '$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 name='staff_id' type = 'Text' value="<?php echo $_POST['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.