weetabix Posted December 13, 2007 Share Posted December 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 change mysql_query($query); to mysql_query($query)or die(mysql_error()); Just want to see what the error is. Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 where is the value for $staffid? Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 its being sent to this page from another one and I apply the following check at the beginning if(!isset($_POST['staffid'])){ echo "Staff ID was not provided!"; die(); } Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Maybe use a Hidden field for the Staffid. then do $staffid = $_POST['staff']; If thats what you ment. Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Just put the STAFF id in the URL http://www.website.com/?staffID=3 Use the HEADER when redirecting the user with the example I showed you from above. I am still a little confused, you will have to give me your full script. Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 Again, the same as before after I enter a valid staff ID I proceed to the page and when I try to change some data there I get the following message Staff ID was not provided! and it remains the same Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 I am re-writing the script, will post it in a sec... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 It should only be checking for STAFF id when the MODE==Upload... Try removing this part of the script if(mysql_num_rows($val)==0){ die('Please provide us with a valid Staff ID'); } Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 Now it says update completed but still the data arent entered in the db. Also, now if I call it without a staff id it still works... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Can you give me a screen shot of the Staff database/table in browse mode? Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 something like this? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 So all the fields need to be changed to be updated ? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 where you say //buttons, does that mean id have to setup another button or use the existing code? I tried it but it'll still wont work Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 where you say //buttons, does that mean id have to setup another button or use the existing code? I tried it but it'll still wont work Your code doesnt work because ALL your buttons are being entered into the DB instead of the textfields. Ill fix it, one sec. Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 ok, thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.