@sultankhan
how admin can change user name and all detail
i have the follwing table
name email pass
name1 email1 pass1
name2 eamil2 pass2
how can i cahnge name1 from my admin page
please any one help me
It would be nice if you can post some code! It would be easier if you have a code about this table and query so it would be easily to help you.
LastMitch
Industrious Poster
4,132 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45
For not making mistakes I recommend you to have one EDIT page where to edit individual users ... something as website/admin/edituser/123
There make just 1 normal form which have all current values, of the user with the id 123, and changed them to whatever you want and submit them.
sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0
Before using down code answer me, do you have user_id column at your table ?
If not you have to add userid column (int with autoincreament).
This way your users will have their unique ID (1,2,3,4,5,6,7,8....);
Other option is to use username as unique id but, I don't recommend that..
Here is an example page for edituser with simple URL as WEBSITE/admin/useredit.php?userid=123 ::
<php
session_start(); // I am not sure you need that but I get your code from above..
$user_id = (int)$_GET['userid']; // this I get from the url the userid param.
if($user_id < 1) {
header('Location: redirectpage.php'); //I think that userid should be 1 or greatter..
}
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("test",$conn);
if(isset($_POST["submit"])){
$sql_update = sprintf("UPDATE users SET name='%s',email='%s',pass='%s' WHERE userid={$user_id}",
mysql_real_escape_string($_POST["name"]),
mysql_real_escape_string($_POST["email"]),
mysql_real_escape_string($_POST["pass"]));
$update = mysql_query($sql_update,$conn) or die(mysql_error());
if($update){
echo "User updated";
}
}
$sql = "SELECT * users WHERE userid={$user_id}"; //userid is the name of your columnt.. I dont know it
$result=mysql_query($sql,$conn) or die(mysql_error());
$user_data = mysql_fetch_row($result);
?>
<form method="post" action="">
<input type="text" name="name" value="<?php echo $user_data['name']; ?>" />
<input type="text" name="email" value="<?php echo $user_data['email']; ?>" />
<input type="text" name="pass" value="<?php echo $user_data['pass']; ?>" />
<input type="submit" name="submit" value="Save" />
</form>
sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0
Please check PHP documantation for such things as how header(location) works...
http://php.net/manual/en/function.header.php
(It may not work if you have ECHO something or output any html code before it)
If you have ID as primary and its autoincreament its unique too.
sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0
sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0