/    Sign up×
Community /Pin to ProfileBookmark

how to get update page to work?????

i am working on an admin. and i have a page where it shows all of the members that have been inserted into the database through a form. the page has a delete column where you can delete members, which i have working, and i have an update column, the page which i need help on.
when i click on the update link, it goes to the update page,and the form fields are supposed to have the members information side of them so that you can change the information. the fields do not do that, and i’m not sure why. the only field that shows information is the member id field.
if anyone could help me out in getting this update page to work, then that would be appreciated. here’s the code i’m using below.

[code=php]
session_start();
do_html_header(‘Administration’);
error_reporting(E_ALL ^ E_NOTICE);
$tblname = “members”;
$host=”localhost”;
$dbuser=”mwooten1″;
$dbpass=”****”;
$database=”higgins”;
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die (“Unable to select database”);
$user_name = “”;
$user_email = “”;
$staddress = “”;
$city = “”;
if (isset($_POST[‘memberid’])){
$user_name = (isset($_POST[“user_name”]) ? $_POST[“user_name”] : “”);
$user_email = (isset($_POST[“user_email”]) ? $_POST[“user_email”] : “”);
$staddress = (isset($_POST[“staddress”]) ? $_POST[“staddress”] : “”);
$city = (isset($_POST[“city”]) ? $_POST[“city”] : “”);

if (!get_magic_quotes_gpc()) {
$user_name=addslashes($user_name);
$user_email = addslashes($user_email);
$staddress = addslashes($staddress);
$city = addslashes($city);
}
}
else
{
$memberid=(isset($_GET[‘id’]) ? intval($_GET[‘id’]) : “”);
if ($memberid) {
$query=”SELECT * FROM $tblname WHERE memberid='”.$memberid.”‘”;
$result=mysql_query($query);
$row=mysql_fetch_array($result);
if ($row) {
$user_name=$row[‘$user_name’];
$user_email = $row[‘$user_email’];
$staddress = $row[‘$staddress’];
$city = $row[‘$city’];
}
else {
$memberid=””;
echo “<h3>Invalid ID</h3><a href=”showmembers.php”>Return to Show Members</a>”;
}
}
}
if (isset($_POST[‘submit’])) {
$sql = “UPDATE $tblname SET user_name='”.$user_name.”‘, user_email='”.$user_email.”‘, $staddress='”.$staddress.”‘, city='”.$city.”‘”;
$sql.=” WHERE memberid='”.$memberid.”‘”;
$result = mysql_query($sql) or die (mysql_error());
echo “<h3>Record Updated!!</h3><a href=’showmembers.php’>Back to Show Members</a><br><br>”;
}
else
{
echo “<h3>Information has not been submitted Yet!</h3><a href=’showmembers.php’>Back to Show Members</a><br><br>”;
}

if ($memberid) {
$table_output='<table border=”0″ cellspacing=”2″ cellpadding=”2″>’;
$table_output.='<form action=”edit2.php” method=”post” enctype=”multipart/form-data”>’;
$table_output.='<input type=”hidden” name=”memberid” value=”‘.$memberid.'”>’;
$table_output.='<tr>’;
$table_output.='<td valign=”top”>ID:</td> <td><input type=”text” name=”memberid” disabled value=”‘.htmlspecialchars(stripslashes($memberid)).'”>’;
$table_output.='</td></tr><tr>’;
$table_output.='<td valign=”top”>User Name:</td> <td><input type=”text” name=”user_name” value=”‘.htmlspecialchars(stripslashes($user_name)).'”>’;
$table_output.='</td></tr><tr>’;
$table_output.='<td valign=”top”>User Email:</td> <td><input type=”text” name=”user_email” value=”‘.htmlspecialchars(stripslashes($user_email)).'”>’;
$table_output.='</td></tr><tr>’;
$table_output.='<td valign=”top”>Street Address:</td><td><input type=”text” name=”staddress” value=”‘.htmlspecialchars(stripslashes($staddress)).'”>’;
$table_output.='</td></tr><tr>’;
$table_output.='<td valign=”top”>City:</td><td><input type=”text” name=”city” value=”‘.htmlspecialchars(stripslashes($city)).'”>’;
$table_output.='</td></tr>
$table_output.='<tr>’;
$table_output.='<td></td><td><input type=”submit” name=”submit” value=”submit”><input type=”reset” /></td>’;
$table_output.='</tr>’;
$table_output.='</form></table>’;
echo $table_output;

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 05.2005 — I think it might be in this section:
[code=php]
if ($memberid) {
$query="SELECT * FROM $tblname WHERE memberid='".$memberid."'";
$result=mysql_query($query);

$row=mysql_fetch_array($result);
if ($row) {
$user_name=$row['$user_name'];
$user_email = $row['$user_email'];
$staddress = $row['$staddress'];
$city = $row['$city'];
}
[/code]

Instead of [b]$row['$user_name'][/b], you want [b]$row['user_name'][/b] (assuming that "user_name" is the name of the column in the table), repeating that change for the other $row[] results, too.
Copy linkTweet thisAlerts:
@mikewootenauthorSep 05.2005 — the problem is fixed, the update is working, thank you....

thats what i had to fix is $user_name=$row['$user_name']; to $user_name=$row['user_name']; and i also deleted an extra $ in my sql update statement, now it works great.

thanks
×

Success!

Help @mikewooten spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...