...

View Full Version : Users not updating



harlequin2k5
10-28-2006, 11:46 PM
I had a similar issue earlier today when I was building my add users and I found that I was using the wrong table name

no errors are displaying at all now so I'm totally at a loss...


if (isset($_GET['user']))
{

$query="SELECT * FROM tblUsers where UserID='" . $_GET['user'] . "'";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);

if($num==1)
{
$row=mysql_fetch_assoc($result);
}

echo "\n<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">";
echo "<p>\n";
echo "<label for=\"first\">First Name:</label>\n";
echo "<input type=\"text\" name=\"first\" value=\"";

if(isset($_POST['first']))
{
echo $_POST['first'];
}
else
{
echo $row['UserFirstName'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"last\">Last Name:</label>\n";
echo "<input type=\"text\" name=\"last\" value=\"";

if(isset($_POST['last']))
{
echo $_POST['last'];
}
else
{
echo $row['UserLastName'];
}
echo "\" />\n";
echo "<p>\n";
echo "<label for=\"uid\">User ID:</label>\n";
echo "<input type=\"text\" name=\"uid\" value=\"";

if(isset($_POST['uid']))
{
echo $_POST['uid'];
}
else
{
echo $row['UserID'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"upw\">Password:</label>\n";
echo "<input type=\"text\" name=\"upw\" value=\"";

if(isset($_POST['upw']))
{
echo $_POST['upw'];
}
else
{
echo $row['UserPassword'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"type\">Type:</label>\n";
echo "<input type=\"text\" name=\"type\" value=\"";

if(isset($_POST['type']))
{
echo $_POST['type'];
}
else
{
echo $row['UserType'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"title\">Title:</label>\n";
echo "<input type=\"text\" name=\"title\" value=\"";

if(isset($_POST['title']))
{
echo $_POST['title'];
}
else
{
echo $row['UserTitle'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"cell\">Cell:</label>\n";
echo "<input type=\"text\" name=\"cell\" value=\"";

if(isset($_POST['cell']))
{
echo $_POST['cell'];
}
else
{
echo $row['UserCell'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"email\">Email:</label>\n";
echo "<input type=\"text\" name=\"email\" value=\"";

if(isset($_POST['email']))
{
echo $_POST['email'];
}
else
{
echo $row['UserEmail'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"active\">Active:</label>\n";
echo "<input type=\"checkbox\" name=\"active\" value=\"";

if(isset($_POST['active']))
{
echo $_POST['active'];
}
else
{
echo $row['UserActive'];
}
echo "\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<input type=\"submit\" name=\"updateuser\" value=\"Update User\" />\n";
echo "</p>\n";
echo "</form>\n";
if (isset($_POST['updateuser']))
{
$first=$_POST['first'];
$last=$_POST['last'];
$uid=$_POST['uid'];
$upw=$_POST['upw'];
$type=$_POST['type'];
$title=$_POST['title'];
$cell=$_POST['cell'];
$email=$_POST['email'];
$active=$_POST['active'];

$query="UPDATE tblUsers SET UserFirstName='$first', UserLastName='$last', UserID='$uid', UserPassword='$upw', UserTitle='$title', UserCell='$cell', UserEmail='$email', UserActive='$active' where UserID='" . $_GET['user'] . "'";
$result=mysql_query($query) or die(mysql_error());
if ($result)
{
echo "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">Record updated successfully.</p>";
}
else
{
echo "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">Record not updated.</p>";
}
}

}


any help is appreciated!

Brandoe85
10-29-2006, 12:10 AM
Hi,

On the form action tack on the user as well, looks like your if statement for the isset($_GET['user']) will fail:

echo "\n<form action=\"" . $_SERVER['PHP_SELF'] . "?user=" . $_GET['user'] . "\" method=\"post\">";

Good luck;

harlequin2k5
10-29-2006, 12:24 AM
while that option does work - the users still are not updating and there still aren't any errors

putting the user back into the form action also forces the form to remain on the page which I also do not want...

lemme rephrase that - all fields update but the active field (checkbox)

harlequin2k5
10-29-2006, 04:38 PM
well I wound up splitting the page into add and update pages (which I didn't want to do)

my checkboxes still do not work on either the adduser or updateuser pages - since I've never used checkboxes on a form in a php page I have no idea what I've done wrong - all I want to do is set a user to either active or inactive...

this is the php from the adduser page - I'm hoping that whatever changes are made would be good to use for the userupdate page as well?


<?
doconnect();

if (isset($_POST['adduser']))
{
echo "\n<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">";
echo "<p>\n";
echo "<label for=\"first\">First Name:</label>\n";
echo "<input type=\"text\" name=\"first\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"last\">Last Name:</label>\n";
echo "<input type=\"text\" name=\"last\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"uid\">User ID:</label>\n";
echo "<input type=\"text\" name=\"uid\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"upw\">Password:</label>\n";
echo "<input type=\"text\" name=\"upw\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"type\">Type:</label>\n";
echo "<input type=\"text\" name=\"type\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"title\">Title:</label>\n";
echo "<input type=\"text\" name=\"title\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"cell\">Cell:</label>\n";
echo "<input type=\"text\" name=\"cell\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<label for=\"email\">Email:</label>\n";
echo "<input type=\"text\" name=\"email\" value=\"\" />\n";
echo "</p>\n";
echo "<label for=\"active\">Active:</label>\n";
echo "<input type=\"checkbox\" name=\"active\" value=\"\" />\n";
echo "</p>\n";
echo "<p>\n";
echo "<input type=\"submit\" name=\"addnewuser\" value=\"Add New User\" />\n";
echo "</p>\n";
echo "</form>\n";
}

if (isset($_POST['addnewuser']))
{
$first=$_POST['first'];
$last=$_POST['last'];
$uid=$_POST['uid'];
$upw=$_POST['upw'];
$type=$_POST['type'];
$title=$_POST['title'];
$cell=$_POST['cell'];
$email=$_POST['email'];
$active=$_POST['active'];
$error=array();

if (strlen(trim($_POST['first']))==0)
{
$error['author'] = 'A first name is required.';
}
if (strlen(trim($_POST['uid']))==0)
{
$error['title'] = 'A user id is required.';
}
if (strlen(trim($_POST['type']))==0)
{
$error['content'] = 'What type of user?';
}
if (count($error)==0)
{
$query="INSERT INTO tblUsers (UserFirstName, UserLastName, UserID, UserPassword, UserType, UserTitle, UserCell, UserEmail, UserActive) VALUES ('$first', '$last', '$uid', '$upw', '$type', '$title', '$cell', '$email', '$active')";
$result=mysql_query($query) or die(mysql_error());
if($result)
{
echo "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">A new user has been added.</p>";
}
}
else
{
foreach($error as $err)
{
echo "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">" . $err . "</p>";
}
}
}

?>

harlequin2k5
10-29-2006, 10:21 PM
fwiw...I changed the active field to a text field and it's fine now :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum