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

Member Avatar for LastMitch

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

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>

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";
    ?>

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.

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.

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.

@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

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>

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

what should i write insted of redirectpage.php

it give the erorr the page is not redirectly properly

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.

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,

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

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

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

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.

dear it doing nothing

did you redirect the the page to your action script?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.