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