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
https://forums.phpfreaks.com/topic/80996-solved-edit-database/
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
https://forums.phpfreaks.com/topic/80996-solved-edit-database/#findComment-410889
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
https://forums.phpfreaks.com/topic/80996-solved-edit-database/#findComment-410894
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
https://forums.phpfreaks.com/topic/80996-solved-edit-database/#findComment-410897
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.