Code: Select all
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","db21","passwort");
//select which database you want to edit
mysql_select_db("db21");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from users order by uid");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$lname=$r["lname"];//take out the title
$fname=$r["fname"];//take out the title
$uid=$r["uid"];//take out the id
//make the title a link
echo "<a href='edit1.php?cmd=edit&uid=$uid'>$fname $lname - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$uid = $_GET["uid"];
$sql = "SELECT * FROM users WHERE uid=$uid";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit1.php" method="post">
<input type=hidden name="uid" value="<?php echo $myrow["uid"] ?>">
E-Mail-Adresse: <input type="text" name="email" VALUE="<?php echo $myrow["email"] ?>" SIZE=30/><br>
Vorname:
<input type="text" name="fname" VALUE="<? echo $myrow["fname"] ?>"/>
<br>
Name:
<input type="text" name="lname" Value="<? echo $myrow["lname"] ?>"/>
<br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$email = $_POST["email"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$uid = $_POST["uid"];
$sql = "UPDATE users SET email='$email',fname='$fname',lname='$lname' WHERE uid=$uid";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>