Jump to content

form not updating


silverglade

Recommended Posts

I can't get my form to update the database with user personal information. Any help greatly appreciated. Upon submitting the form, it just reloads the page, no information added to the DB. I used the update statement because I want the users to be able to update the info at a later date. Not sure if that was the right thing to do. thank you.

 

 

<?php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);
include('bouncer.php');
$host		= "";
$database 	= "";
$username 	= "";
$password 	= "";

$tbl_name   = "users";

$conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());

if($conn)
{
mysql_select_db($database);

} else {
	echo "failed to select database";
}



$currentUser = $_SESSION['myusername']; // get user from login and make it current user to use for update statement

echo "Login success!<br/>";
echo "Please fill out the form below to add your personal information to the database<br/>";
//////////////////////////////////////////////////////////////////////////////////////////////////
if(isset($_POST['submit'])) 

{	



		$firstname = mysql_real_escape_string( $_POST['first']);
		$lastname = mysql_real_escape_string( $_POST['last']);
		$dob = mysql_real_escape_string( $_POST['dob']);
		$gender = mysql_real_escape_string( $_POST['gender']);






$result= mysql_query ( "UPDATE users SET firstname = '$firstname', lastname = '$lastname', dob = '$dob', gender='$gender' WHERE username='$currentUser'") or die(mysql_error());


		if($result)
		{
		echo "your information was updated in the database and is as follows <br/>";
		//put the results on the screen
		echo "<br/> $firstname <br/>";
		echo "<br/>$lastname <br/>";
		echo "<br>$dob <br/> ";
		echo ">$gender <br>";

		} else {
			echo "error, could not update your info to the database </br>";//end if result

		}




}//end if sumbit post statement at top
?>
<html>
<body>
<p> </p>
<p> </p>
<p>

<form action="login_successERROR.php" method="post">
  <p>
    <input type="text" name="first" size="20" /> 
  First name<br />
    <input type="text" name="last" size="20" />
    Last name<br />
    <input name="dob" type="text" size="20" id="dob" />
    Date of Birth<br />
    <input type="text" name="gender" size="20" id="gender" />
  Gender <br />
  
    <input type="submit" value="Add personal information to database" />
    <input type="reset" value="Reset fields" />
  </p>
  </p>
</form> 

<p><a href="index.php">HOME</a></p>
<p> </p>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/246073-form-not-updating/
Share on other sites

Try

 

<?php

if(isset($_POST['submit'])) {	
$firstname = $_POST['first'];
$lastname = $_POST['last'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];

$result = mysql_query("UPDATE users SET firstname = '{$firstname}', lastname = '{$lastname}', dob = '{$dob}', gender='{$gender}' WHERE username = '{$currentUser}'") or die(mysql_error());

if($result) {
	echo "your information was updated in the database and is as follows<br />";
	//put the results on the screen
	echo "<br />{$firstname}<br />";
	echo "<br />{$lastname}<br />";
	echo "<br />{$dob}<br />";
	echo "<br />{$gender}<br />";
} else {
	echo "error, could not update your info to the database<br />";
}
}
?>
<html>
<body>
<form method="post" target="_self" action="">
    <input type="text" name="first" size="20" /> 
    First name<br />
    <input type="text" name="last" size="20" />
    Last name<br />
    <input name="dob" type="text" size="20" id="dob" />
    Date of Birth<br />
    <input type="text" name="gender" size="20" id="gender" />
    Gender <br />
    
    <input type="submit" value="Add personal information to database" />
    <input type="reset" value="Reset fields" />
</form> 

<p><a href="index.php">HOME</a></p>
</body>
</html>

 

I don't know if this will help you though, I copied your code and edited a little.

Make sure you double check your variables and whats going into your database as one symbol or letter can break everything.

Link to comment
https://forums.phpfreaks.com/topic/246073-form-not-updating/#findComment-1263745
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.