Jump to content

passing data into MySQL


pinochio

Recommended Posts

I need to create a registration page that will pass data into MySQL. I created 2 pages. first wher user will be able to enter required information and second that connects to MySQL and transfers all data. When I click submit (Next) button on 1st page absolutely nothing happens 1st page does not go to the 2nd page. I would like to get an advise what can cause this problem. Thank you very much!!!

 

1st page

<?php
session_start();
$FName = "";
$LName = "";
$HAddress = "";
$HCity = "";
$HState = "";
$HZip = "";
$HPhone = "";
$HEmail = "";
if (isset($_SESSION['First Name']))
$FName = $_SESSION['First Name'];
if (isset($_SESSION['Last Name']))
$LName = $_SESSION['Last Name'];
if (isset($_SESSION['Home Address']))
$HAddress = $_SESSION['Home Address'];
if (isset($_SESSION['Home City']))
$HCity = $_SESSION['Home City'];
if (isset($_SESSION['Home State']))
$HState = $_SESSION['Home State'];
if (isset($_SESSION['Home Zip']))
$HZip = $_SESSION['Home Zip'];
if (isset($_SESSION['Home Phone']))
$HPhone = $_SESSION['Home Phone'];
if (isset($_SESSION['Home Email']))
$HEmail = $_SESSION['Home Email'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Created on: 9/30/2009 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title></title>
</head>
<body>
<h1>Welcome</h1>
<h2>personal information</h2>
<form action="Register.php" method="post"> 
<p>First Name <input type="text" name="First Name" value='<?= $FName  ?>' /></p>
<p>Last Name  <input type="text" name="Last Name" value='<?= $LName  ?>' /></p>
<p>Address    <input type="text" name="Home Address" value='<?= $HAddress  ?>' /></p>
<p>Home City  <input type="text" name="Home City" value='<?= $HCity ?>' /></p>
<p>Home State <input type="text" name="Home State" value='<?= $HState  ?>' />  Home Zip
<input type="text" name="Home Zip" value='<?= $HZip ?>' /></p>Personal Phone Number <input type="text" name="Home Phone" value='<?= $HPhone  ?>' /></p>
<p> Personal E-mail <input type="text" name="Home Email" value='<?= $HEmail  ?>' /></p>
<p><input type="hidden" name="SESSIONID" value='<?php echo session_id() ?>' />
<input type="submit" value="NEXT STEP" /></p>
</form>
<h3>Thank you!!!</h3>
</body>

 

2nd Page

<?php
session_start();
if (!isset($_SESSION['First Name']) ||
!isset($_SESSION['Last Name']) ||
!isset($_SESSION['Home Address']) ||
!isset($_SESSION['Home City']) ||
!isset($_SESSION['Home State']) ||
!isset($_SESSION['Home Zip']) ||
!isset($_SESSION['Home Phone']) ||
!isset($_SESSION['Home email']))
header("location:Pinfo.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Professional Conference</title>
</head>
<body>
<h1>Registration</h1>
<?php
$DBConnect = @mysqli_connect("localhost", "root", "")//MYSQl connection
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
$DBName = "conference"; //create database
if (!@mysqli_select_db($DBConnect, $DBName)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
	Or die("<p>Unable to execute the query.</p>"
	. "<p>Error code " . mysqli_errno($DBConnect)
	. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the database.</p>";
mysqli_select_db($DBConnect, $DBName);
}
$TableName = "attendees";//create table
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (!$QueryResult) {
	$SQLstring = "CREATE TABLE $TableName (attendeeID SMALL INT NOT NULL AUTO_INCREMENT PRIMARY KEY, firstName VARCHAR(40), lastName VARCHAR(40), home address VARCHAR(40), home city VARCHAR(40),home state VARCHAR(2),home zip VARCHAR(10), home phone VARCHAR(40),home email VARCHAR(40),)";
	$QueryResult = @mysqli_query($DBConnect, $SQLstring)
		Or die("<p>Unable to create the $TableName table.</p>"
		. "<p>Error code " . mysqli_errno($DBConnect)
		. ": " . mysqli_error($DBConnect)) . "</p>";
	echo "<p>Successfully created the $TableName table.</p>";
}
$SQLstring = "SELECT * FROM $TableName WHERE firstName='{$_SESSION['First Name']}' && lastName='{$SESSION['Last Name']}'";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
		. "<p>Error code " . mysqli_errno($DBConnect)
		. ": " . mysqli_error($DBConnect)) . "</p>";
$NumRows = mysqli_num_rows($QueryResult);
if ($NumRows > 0)
exit("<p>Your are already registered for the conference!</p>
	<form action='PersonalInfo.php' method='post'>
	<p><input type='submit' value='Back' /></p>
	</form>");
$FName = addslashes($_SESSION['firstName']);
$LastName = addslashes($_SESSION['lastName']);
$HAddress = addslashes($_SESSION['address']);
$HCity = addslashes($_SESSION['city']);
$HState = addslashes($_SESSION['state']);
$HZip = addslashes($_SESSION['zip']);
$HPhone = addslashes($_SESSION['phone']);
$HEmail = addslashes($_SESSION['email']);

$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
		. "<p>Error code " . mysqli_errno($DBConnect)
		. ": " . mysqli_error($DBConnect)) . "</p>";

mysqli_close($DBConnect);
?>
<p>You have successfully registered.</p>


</body>
</html>

  Thank you very much!!!

Link to comment
https://forums.phpfreaks.com/topic/176145-passing-data-into-mysql/
Share on other sites

I would guess that the first conditional statement is returning true and redirecting back to Pinfo.php. Make sure the $_SESSION variable contains what you expect. Try doing a print_r($_SESSION) at the beginning of your registration page and comment out the header redirect.

I'd have to concur with lemmin, I think you'll find they all fail. I'm guessing all the variables at the top of register.php should be $_POST not $_SESSION. Also assuming that is right, quick tip. I don't believe $_POST['First Name'] will be valid, I think it will have automatically been converted to $_POST['First_Name'].

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.