abrahamgarcia27 Posted July 2, 2011 Share Posted July 2, 2011 I am new to programming and i wanted to see how i can update data that is already in my database through an edit button, but i want it to edit only that member_id (primary key) my database is composed of the following member_id (auto increment) firstname lastname login password usertype $sql = mysql_query("SELECT * FROM newUsers2 ORDER BY member_id ASC"); $id = 'member_id'; $fname = 'firstname'; $lname = 'lastname'; $login = 'login'; echo '<ul class="list">' ; echo '<li class="heading">'; echo '<span class="id">ID </span>' ; echo '<span class="firstname">FIRST NAME </span>' ; echo '<span class="lastname">LAST NAME </span>' ; echo '<span class="login">LOGIN </span>' ; echo '<span class="userType">ADMIN RIGHTS</span>'; echo '<span class="edit">EDIT</span>'; echo '</li>' ; while ($rows = mysql_fetch_assoc($sql)){ if($rows['userType'] == 1) { $userTypeValue = "YES"; } else { $userTypeValue = "NO"; } echo '<li class="entries">' ; echo '<span class="id">' .$rows[$id]. '</span>' ; echo '<span class="firstname">' .$rows[$fname]. '</span>' ; echo '<span class="lastname">' .$rows[$lname]. '</span>' ; echo '<span class= "login">' .$rows[$login]. '</span>'; echo '<span class="userType">' .$userTypeValue. '</span>' ; echo '<span class="edit"> <a href="edituser.php">EDIT</a> </span>'; echo '</li>' ; } echo '</ul>' ; ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 2, 2011 Share Posted July 2, 2011 In the Edit link you need to pass the member id as a parameter of the anchor tag. Such as: echo "<span class=\"edit\"> <a href=\"edituser.php?id={$rows[$id]}\">EDIT</a> </span>"; Then on the edituser.php page you can access that ID value using $_GET['id']. On that page you can use that value to 1) run a query to get the current values to populate the form and 2) populate a hidden field in that form with the ID. Then when the user POSTs that page take the ID and the other form field values (escape the values) and run an update query. However, if this page does not require authentication anyone can edit any record by trying different IDs in the URL Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted July 2, 2011 Author Share Posted July 2, 2011 how would you structure a update query i know for inserting i used this, but how would i structure a Update Query? //Create INSERT query $qry = "INSERT INTO newUsers2(firstname, lastname, login, passwd, userType) VALUES('$fname','$lname','$login','".md5($_POST['password'])."', '$userType')"; $result = @mysql_query($qry); Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 2, 2011 Share Posted July 2, 2011 Depending on what fields you want to allow for update: UPDATE newUsers2 SET firstname = $newFirtsname, lastname = $newLastname WHERE id = $idToBEUpdated 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.