943,187 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 775
  • PHP RSS
Jun 26th, 2010
0

Php update problem

Expand Post »
k guys so I have a login script, then an admin page, only for admins ><. But on the admin page I want them to be able to change there information, like email, username, password, account type, by the way my data base has all of these things acc type username password email id. The acc type is accountype and it is an "Enum" and a is normal users and c is admin's. They need to have the C type to get in but when they update it, it says it all works. But it always makes the username to "0". Help please. Here are the two files
PHP Syntax (Toggle Plain Text)
  1. admin_page.php
  2. <?php
  3. //include the database info to connect
  4. include ('update.php');
  5. if (!isset($_SESSION['admin'])) {
  6. echo 'You need to be logged in, and be an admin to view this page!';
  7. die();
  8. } else {
  9. echo 'Welcome to the admin page, ';
  10. echo $_SESSION['id'];
  11. echo ', Feel free to edit, update or delete all of the users information';
  12. }
  13. ?>
  14. <html>
  15. <head>
  16. <title> Admin Page </title>
  17. </head>
  18. <body>
  19. <br />
  20. <a href="login_success.php"> Home Page </a><br />
  21. <a href="logout.php"> Logout </a><br /><br />
  22. <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  23. <tr>
  24. <form action="update.php" method="post">
  25. <td>
  26. <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  27. <tr>
  28. <td colspan="3"><strong>Edit User: <?php echo $_SESSION['id']; ?>'s information </strong></td>
  29. </tr>
  30. <tr>
  31. <td width="78">Username</td>
  32. <td width="6">:</td>
  33. <td width="294"><input name="username" type="text"></td>
  34. </tr>
  35. <tr>
  36. <td>Password</td>
  37. <td>:</td>
  38. <td><input name="password" type="password"></td>
  39. </tr>
  40. <tr>
  41. <td width="78">Email</td>
  42. <td width="6">:</td>
  43. <td width="294"><input name="email" type="text"></td>
  44. </tr>
  45. <tr>
  46. <td width="78">Account Type</td>
  47. <td width="6">:</td>
  48. <td width="294"><select name="accounttype">
  49. <option value="a">Normal User</option>
  50. <option value="c">Admin</option>
  51. </td>
  52. </select>
  53. </tr>
  54. <tr>
  55. <td>&nbsp;</td>
  56. <td>&nbsp;</td>
  57. <td><input type="submit" name="submit" value="submit"></td>
  58. </tr>
  59. </table>
  60. </td>
  61. </form>
  62. </tr>
  63. </table>
  64. </body>
  65. </html>
  66.  
and update.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. //database connect information
  4. $host = 'localhost'; //mysql server domain
  5. $user = 'grant'; //mysql username
  6. $pass = 'root'; //mysql password
  7. $db = 'login'; //mysql database name
  8.  
  9. $connect = @mysql_connect ($host,$user,$pass);
  10.  
  11. $select = @mysql_select_db($db,$connect);
  12.  
  13. //action for submit the button
  14. if (isset ($_POST['submit'])) {
  15. //gets information from the feilds username password and email
  16. $username = $_POST['username'];
  17. $password = $_POST['password'];
  18. $email = $_POST['email'];
  19. $accounttype = $_POST['accounttype'];
  20. $updte = $_SESSION['id'];
  21. $updtepass = $_SESSION['od'];
  22.  
  23. //checks to see empty username or password
  24. if (!empty ($username) && !empty ($password) && !empty ($email) && !empty ($accounttype)) {
  25. $sql = mysql_query("update members SET username='$username' and password='$password' and email='$email' and accounttype='$accounttype'
  26. WHERE username='$updte' and password='$updtepass'");
  27. echo 'User ';
  28. echo $_SESSION['id'];
  29. echo 's information was updated';
  30. echo '<html><body><br /><a href="admin_page.php">Return to admin page</a></body></html>';
  31. } else {
  32. echo 'You are not aloud to change a users information like this';
  33.  
  34. }
  35.  
  36. }
  37. ?>
Please help and tell me if you need any other of the files.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Grantism is offline Offline
10 posts
since Jun 2010
Jun 26th, 2010
0
Re: Php update problem
Hi and welcome to daniweb. Could you please rephrase that in a way that directly addresses the problem your experiencing. It is hard to understand what the question is or what the problem is.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,003 posts
since Sep 2007
Jun 27th, 2010
0
Re: Php update problem
maybe theres a problem with your database, maybe the data type of field username is int and not varchar, try checking your table fields as i check there is no problem on getting the username.
Reputation Points: 32
Solved Threads: 60
Posting Pro in Training
vaultdweller123 is offline Offline
484 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: unterminated string constant
Next Thread in PHP Forum Timeline: Explode() for XML output using group_concat in SQL query help please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC