adam291086 Posted December 10, 2007 Share Posted December 10, 2007 I have this simple script <?php include 'config.php'; $conn; $sql = "SELECT * FROM tbl_auth_user"; $result = mysql_query("$sql"); while($row = mysql_fetch_array($result)) { $User = $row["user_name"]; ?> <form action="updateuser.php" method="post" name="add" class="maintext" id="add"> <label> User Name: <input type="text" name="User_Name" id= User_Name value=<?php echo $User; ?> /> <br /> <input type="submit" name = "Edit" id = $User/> </label> <?php } ?> </form> </tr> That takes information from the database and while there is information print out cetain details. This is for an edit user item. What i cant think of how to do is this. When a user clicks on an edit button it submits that particular user name to the updateuser.php. At the moment it is only submitting the final username from the while loop. Quote Link to comment Share on other sites More sharing options...
tapos Posted December 10, 2007 Share Posted December 10, 2007 <form action="updateuser.php" method="post" name="add" class="maintext" id="add"> just change this to the following <form action="updateuser.php" method="post" class="maintext" > U can't use the same name for multiple variables without using array. If so the last variable value will be available. so u just get the last result Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 10, 2007 Author Share Posted December 10, 2007 ok, i have done that, but i am still getting the same problem. This is how i echo out the information in the updateuser.php $User = $_POST["User_Name"]; echo $User; Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Since all you are really doing is going to the update page you should be building a list of links. I suggest something like... [....] while($row = mysql_fetch_array($result)) { $user = $row['user_name']; /* Output the links however you want, I recommend using the user id instead of name */ echo '<a href="updateuser.php?user='.urlencode($user).'">'.$user.'</a>'; } [...] You will need to change you update user page to work with the $_GET values instead of $_POST. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 10, 2007 Author Share Posted December 10, 2007 thanks, works a treat. Don't know why i didn't think of that. Quote Link to comment Share on other sites More sharing options...
tapos Posted December 10, 2007 Share Posted December 10, 2007 <?php include 'config.php'; $conn; $sql = "SELECT * FROM tbl_auth_user"; $result = mysql_query("$sql"); while($row = mysql_fetch_array($result)) { $User = $row["user_name"]; ?> <form action="updateuser.php" method="post" class="maintext" > <label> User Name: <input type="text" name="User_Name" id= User_Name value=<?php echo $User; ?> /> <br /> <input type="submit" name = "Edit" id = $User/> </label> </form> <?php } ?> Just use this. 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.