weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 still, it doesnt update anything Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 still nothing by the way, then the staff id is passed to the script its done by GET. I now changed it to POST and still nothing :S Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 still nothing by the way, then the staff id is passed to the script its done by GET. I now changed it to POST and still nothing :S ' You have to fill in the Staff_ID field, then lets say the username field. Try that. Can you link me to your site where this script is? Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 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>" ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 Yeah, apparently that was the problem! All wrong? eeek.... expand that pls I'm gonna try the other script... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 ok, one more question <td><input type = 'Text' name='staff_id' value='".$_POST['staff_id']."'></td> doesnt this need the php brackets to work? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 yeah i kinda thought so but heres what i get when testing Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 my mistake lol Make it this: <td><input name='staff_id' type = 'Text' value="<?php echo $_POST['staff_id']; ?>"></td> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 Oh god Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /dos/html/staffUpdate.php on line 142 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 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> Quote Link to comment Share on other sites More sharing options...
weetabix Posted December 13, 2007 Author Share Posted December 13, 2007 Everything works fine, just had another look at it. Btw, you're my god now thanks for everything!!!!!! Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Haha, I am glad to help you out. Although my timing could have been better. Thankyou. p.s. Do not forget to Mark Topic As Solved 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.