Jump to content

UPDATE problems


ashrobbins87

Recommended Posts

I have a form which displays user data from the database and I want to be able to let the user change it and resubmit it to the database. This is the code for the form....

I know that $id, $f, $s and $u all have data in them because they display on the page, but I cannot update the new data that is entered in the form. I'm not sure if this is a PHP or MySQL problem. Any help appreciated!

 

<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\" value=\""; echo @$_POST['upload'] ? $_POST['upload'] : ''; echo "\">
<table>
<tr><td>First Name: </td><td><input type=\"text\" name=\"firstname\" size=\"20\" value=".$f." /></tr>
<tr><td>Surname: </td><td><input type=\"text\" name=\"surname\" size=\"20\" value=".$s." /></tr>
<tr><td>Username: </td><td><input type=\"text\" name=\"username\" size=\"20\" value=".$u." /></tr>
<tr><td>New Password: </td><td><input type=\"text\" name=\"newpassword\" size=\"20\" value=\"Enter New Password\" /></tr>
<tr><td>Re-enter Password: </td><td><input type=\"text\" name=\"confirmpassword\" size=\"20\" value=\"Confirm New Password\" /></tr>
</table>

<br/><br/>
";

$new_f = $_POST['firstname'];
$new_s = $_POST['surname'];
$new_u = $_POST['username'];
$new_p = $_POST['newpassword'];
$conf_p = $_POST['confirmpassword'];

if($new_f)
{	
if (mysqli_connect_errno())
{
	printf("Connect failed: %s\n", mysqli_connect_error());
	exit();
}
else
{

	$updateUser_sql = "UPDATE cms_users
				SET firstname ='".$new_f."' AND surname ='".$new_s."' AND username ='".$new_u."'
				WHERE id = '".$id."'";
	$updateUser_res = mysqli_query($mysqli, $updateUser_sql);

	if ($updateUser_res === TRUE)
	{
		echo "Update Successful";
		header ("Location: user.php");
	}
	else
	{
		printf("Could not update page: %s\n", mysqli_error($mysqli));
	}
	mysqli_close($mysqli);
}
}

echo"<table>
<tr>
<td><input type=\"submit\" name=\"update\" value=\"Update User\"></td>
<td><a href=\"javascript:eventWindow('cms/deletevalidation.php');\"><input type=\"submit\" name=\"delete\" value=\"Delete\"></a></td>
</tr>
</table></form>";

Link to comment
https://forums.phpfreaks.com/topic/150706-update-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.