Jump to content

UPDATING data through a php form


Recommended Posts

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

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.