Jump to content

[SOLVED] edit database


adam291086

Recommended Posts

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. 

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

  <?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.