I have this code which consits of four pages. It is a simple update routine that turned out not to be so simple. I can get the values for password and email to display correctly, but for some reason can not get the username to display. I am using MySQL.
Here is the code:
(mod_edit: added
Code: Select all
tags to code)
==== List.php ====Code: Select all
<head>
<style>
td{
font-family:arial;
font-size:8pt;
color:#696969;
}
.wh{
color:white;
}
.more{
color:#0974A6;
}
.menu{
color:#748B3D;
}
</style>
</head>
<link href="style.css" rel="stylesheet" media="screen">
<div align="center"> <span class="headers">Password Recovery Profile</span><br>
<br>
<table width="650" cellspacing="2" border="0" cellpadding="1">
<tr bgcolor="#DADADA" align="center">
<td bgcolor="A5E2FF"><font color="#000000">Username</font></td>
<td bgcolor="A5E2FF"><font color="#000000">Password</font></td>
<td bgcolor="A5E2FF"><font color="#000000">E-Mail</font></td>
<td bgcolor="A5E2FF"><font color="#000000">Edit</font></td>
</tr>
<?php
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$result = mysql_query("select * from $db_table where uname != 'sa'");
while($r=mysql_fetch_array($result))
{
$_POST[username]=$r['uname'];
$_POST[password]=$r['pass2'];
$_POST[email]=$r['email'];
print '
<tr>
<td><center>' . $_POST[username] . '</center></td>
<td><center>' . $_POST[password] . '</center></td>
<td>' . $_POST[email] . '</td>
<td><center><a href="index.php?todo=edit&editid=' . $_POST[username] . '">edit</center></td>
</tr>';
}
?>
</table>
</div>Code: Select all
<head>
<style>
td{
font-family:arial;
font-size:8pt;
color:#696969;
}
.wh{
color:white;
}
.more{
color:#0974A6;
}
.menu{
color:#748B3D;
}
</style>
</head>
<?
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$result = mysql_query("SELECT * FROM $db_table WHERE uname=$editid");
$edit = mysql_fetch_array($result);
?>
<form method="post" action="index.php">
<input type="hidden" name="todo" value="update">
<input type="hidden" name="uname" value="<? echo $edit["editid"] ?>">
<table bordercolor="#000000" border="1" align="center" width="40%" height="138" cellpadding="4">
<tr bgcolor="A5E2FF">
<td width="104"><b><font color="#000000">Username:</font></b></td>
<td width="269" bgcolor="A5E2FF"> <font color="#000000">
<? print $edit["uname"] ?>
</font> </td>
</tr>
<tr bgcolor="A5E2FF">
<td width="104">
<p><b><font color="#000000">Password:</font></b></p>
</td>
<td width="269">
<input type="text" name="password" value="<? print $edit["pass2"] ?>">
</td>
</tr>
<tr bgcolor="A5E2FF">
<td width="104"><b><font color="#000000">E-Mail Address:</font></b></td>
<td width="269">
<input type="text" name="email" value="<? print $edit["email"] ?>" size="35">
</td>
</tr>
</table>
<br><div align="center">
<p>
<input type="submit" name="submit" value="Update Profile">
</p>
<? echo $_POST[$username]?>
</div>
<div align="center"></div>
</form>Code: Select all
<?
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
// $result = mysql_query("UPDATE $db_table SET pass2=$password,email=$email WHERE uname='$username'");
$result = mysql_query("UPDATE $db_table SET pass2=$_POST[password], email=$_POST[email] WHERE id=$_POST[username]");
print '
<table border=1>
<tr>
<td>' . $_POST[username] . '</td>
<td>' . $_POST[password] . '</td>
<td>' . $_POST[email] . '</td>
</tr>
</table>';
?>Code: Select all
<?
require("vars.php"); //for database connection vars
switch ($todo) {
case "add":
//dispaly a blank form
$title="Add new entry"; //used by header
require("header.php"); // your page header
require("add.php"); // submits to index.php?todo=save
require("footer.php"); // your page footer
break;
case "edit":
// pull the data from db and plugs into form
$title = "Edit Existing Entry"; // used by header
require("header.php"); // your page header
require("edit.php"); // edits $editid, submits to index.php?todo=update
require("footer.php"); // your page footer
break;
case "delete":
require("delete.php"); // deletes $deleteid from the db
header("Location: index.php"); // go to listing
break;
case "save":
require("save.php"); // add new entry to db
header("Location: index.php"); // go to listing
break;
case "update":
require("update.php"); // update the db where id=$id
header("Location: index.php"); // go to listing
break;
default:
$title = "Viewing All Entries"; // used by header
require("header.php"); // your page header
require("list.php"); //show all entries
require("footer.php"); // your page footer
break;
}
?>All of my database connects seem to work for everything else except this update.
I am also having problems with the list.php page. I want it only to display the info for the current user and not the entire list. I have tried to edit the SQL SELECT statement with a WHERE, but I guess I am not getting that variable either.