Jump to content

PHP Form / MySQL Issue


BMurtagh

Recommended Posts

Hello,

 

I'm working on a project at work in which I'm converting our old excel spreadsheets into an online php+mysql web-based system. I have the add user functionality and delete user functionality working, however I'm stuck with editing a current user's database information. I'm populating an "edit user" form with information from the DB based off of the user's ID#:

 

$query = "SELECT * FROM Users WHERE UserID = '$id'";
if (!$result) {
    echo "Could not successfully run query ($query) from DB: " . mysql_error();
    exit;
}
while($row = mysql_fetch_array($result)) {

echo "<fieldset style=\"width:100\" align=\"center\"><legend><font color=\"#FFFF00\">Edit User Information</font></legend><br />";
echo "<center><form id=\"edituser\" name=\"edituser\" method=\"post\" action="">";
echo "<font color=\"#FFFF00\">Name:</font> <input type=\"text\" name=\"name\" id=\"name\" value=\"".$row['Name']."\">" . "<br /><br /><br />";
echo "<font color=\"#FFFF00\">Username:</font> <input type=\"text\" name=\"username\" id=\"username\" value=\"".$row['Username']."\">" . "<br /><br />";
echo "<font color=\"#FFFF00\">Password:</font> <input type=\"text\" name=\"password\" id=\"password\" value=\"".$row['Password']."\">" . "<br /><br /><br /><br />";
echo "<font color=\"#FFFF00\">Department:</font> <input type=\"text\" name=\"dept\" id=\"dept\" value=\"".$row['Department']."\">" . "<br /><br />";
echo "<font color=\"#FFFF00\">Location:</font> <input type=\"text\" name=\"loc\" id=\"loc\" value=\"".$row['Location']."\">" . "<br /><br /><br /><br />";
echo "<font color=\"#FFFF00\">Printer 1:</font> <input type=\"text\" name=\"print1\" id=\"print1\" value=\"".$row['Printer1']."\">" . "<br /><br />";
echo "<font color=\"#FFFF00\">Printer 2:</font> <input type=\"text\" name=\"print2\" id=\"print2\" value=\"".$row['Printer2']."\">" . "<br /><br />";
echo "<br /><br /><br /></center>";
}

 

The main issue I'm currently running into is once the data is pulled from the DB into the textboxes, I go to click on say Name or any of the fields and it basically takes me back to the previous page (users.php) which is just a SELECT * FROM Users and displays the information in a table. On the users.php page, I have 2 post actions, one for edit & one for del:

 

while($row = mysql_fetch_array($result)) 
{
$edit = "<form method=\"post\" action=\"edituser.php\"><input type=\"hidden\" name=\"UserID\" value=\"".$row['UserID'] ."\"><input type=\"image\" src=\"images/edit.png\" border=\"0\" alt=\"Edit Entry\"></form>";
$delete = "<form method=\"post\" action=\"deluser.php\"><input type=\"hidden\" name=\"UserID\" value=\"".$row['UserID'] ."\"><input type=\"image\" src=\"images/del.png\" border=\"0\" alt=\"Edit Entry\"></form>";
$id = $row['UserID'];
   	echo "<p><tr>";
   	echo "<td>" . $row['UserID'] . "</td>" .
    "<td> " . $row['Name'] . "</td>" .
	"<td> " . $row['Username'] . "</td>" .
	"<td> " . $row['Password'] . "</td>" . 
	"<td> " . $row['Location'] . "</td>" .
	"<td> " . $row['Department'] . "</td>" .
	"<td> " . $row['Printer1'] . "</td>" . 
	"<td> " . $row['Printer2'] . "</td>" . "</td>" . "<td align=\"center\">" .$edit . "</td><td align=\"center\">" . $delete . "</td>";
echo "</tr>";
}
echo "</table></center><br /><br /><p>";

 

I'm still confused/unsure why when after I populate the textboxes with the user's information I'm trying to edit it reverts back. If anyone has any suggestions, tips, or code snippets for a better way to do this, I'm interested. Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.