1.11M Members

how admin can change user name and all detail

 
0
 

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

LastMitch
Deleted Member
 
0
 

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

 
0
 

thanks @lastMitch for reply
the code ia have is the follwing but it delet all names and i dont want to delet all name i just want to update a specific user name emai etc mean if i want to replace name1 with name3 then how can i do this,

 <?php
 $con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

 if ($_POST['submit']) {

 $username = $_POST['name'];

 //if you want to update
 mysql_query("UPDATE users SET name = '$name'");







 }

 ?>






<form method="POST">

Delete username: <input type="submit" name="submit" value="DELETE"/>

</form>
 
0
 

my next code which i have try but this insert value in new lion while i want to replace the name whcih i want to chnge the code is ..........

    <?php
     session_start();session_destroy();
     session_start();
    if($_GET["regname"])
    {
        if($_GET["regpass1"]==$_GET["regpass2"])
        {
        $servername="localhost";
        $username="root";
        $conn=  mysql_connect($servername,$username)or die(mysql_error());
        mysql_select_db("test",$conn);
        $sql="insert into users (name)values('$_GET[regname]')";
        $result=mysql_query($sql,$conn) or die(mysql_error());      
        print "<h1>you have sucessfully email ID</h1>";

        print "<a href='index.php'>go to login page</a>";
        }
        else print "passwords doesnt match";
    }
    else print"invaild input data";
    ?>
 
0
 

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.

 
0
 

thanks @sv3 for reply
i have create edit page which have the above can you give me a code how to edit user profile.
tahnks in advance.

 
0
 

You need to use the WHERE clause to select the proper row to edit.
mysql_query("UPDATE users SET name = '$name' WHERE name='$SelectedNameForExample'");
that will update a specific name.

 
0
 

@Nardcake
i know that method which you have told but i want to edit not like that becoz for this i need "where" for each user so when new user comes how my client will set this i want to change each user name and all details

 
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>
 
0
 

Dear @sv3
yes i have id with name id but i have set as primary key not unique
so i should change that?

 
0
 

what should i write insted of redirectpage.php

 
0
 

it give the erorr the page is not redirectly properly

 
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.

 
0
 

i have nothing before it and it works in other pages mean if i give a page excipt my edit user page mean in which page i have save this code, it give me this error otherwise if i change this page it work but i have no idea that which page i should write there,

 
0
 

Write in your full page url .. as

header('Location: http://mysite.com/mypage.php');
 
0
 

What are you trying to do here? Do you want the user who logged in to inactivate his own account?

 
0
 

Dear @tscina
i want if a user login then how can he see his profile and how can he edit his profile..?

 
0
 

dear @sv3 it give me the follwin error now
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'users WHERE user_id=0' at line 1

 
0
 

You don't have any input type text that's why the code deletes everydata. Try

<form method="POST" action="">
Delete username: <input type="text" name="username" />
<input type="submit" name="submit" value="DELETE"/>
</form>

Then try to insert this in your php code:

    $username=$_POST['username'];

    $query= "DELETE * FROM yourtablename WHERE username='$username'";

But this is not advised as it's better to assign it to a primary key but just to test if it would work the way you want it to I made it basic.

 
0
 

dear it doing nothing

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: