Jump to content

Recommended Posts

I need to pass all $_SESSION variables into MySQL, when I click register I get redirected to my first page and nothing goes to the database. Does somebody have any ideas what might be wrong?

Thank you!!!

<?php
session_start();
if ($_POST['html5Seminar'] == "on")
$_SESSION['HTML5_camp'] = TRUE;
else
$_SESSION['HTML5_camp'] = FALSE;
if ($_POST['PhytonSeminar'] == "on")
$_SESSION['phyton_camp'] = TRUE;
else
$_SESSION['phyton_camp'] = FALSE;
if ($_POST['RubyOnRailsSeminar'] == "on")
$_SESSION['ruby_camp'] = TRUE;
else
$_SESSION['ruby_camp'] = FALSE;

if ($_POST['PerlSeminar'] == "on")
$_SESSION['perl_camp'] = TRUE;
else
$_SESSION['perl_camp'] = FALSE;

if ($_POST['GlassFishSeminar'] == "on")
$_SESSION['glassfish_camp'] = TRUE;
else
$_SESSION['glassfish_camp'] = FALSE;
$Required = "<span style='color:red'>**REQUIRED**</span>";
$Missing = FALSE;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Training Camp 2009</title>
</head>
<body>
<h1>Review of entered information</h1>
<p>STEP 4:Review entered information.</p>
<table border="1" cellpadding="5">
<tr valign="top"><td>
<h2>Enter Personal Information</a></h2>
<?php
if (isset($_SESSION['FirstName']))
echo "<p>First Name: {$_SESSION['FirstName']}<br />";
else {
echo "<p>First Name: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['LastName']))
echo "Last Name: {$_SESSION['LastName']}<br />";
else {
echo "Last Name: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['HomeAddress']))
echo "Home Address: {$_SESSION['HomeAddress']}<br />";
else {
echo "Home Address: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['HomeCity']))
echo "City: {$_SESSION['HomeCity']}<br />";
else {
echo "City: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['HomeState']))
echo "State: {$_SESSION['HomeState']}<br />";
else {
echo "State: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['HomeZip']))
echo "Zip Code: {$_SESSION['HomeZip']}<br />";
else {
echo "Zip Code: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['HomePhone']))
echo "Phone: {$_SESSION['HomePhone']}<br />";
else {
echo "Phone: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['HomeEmail']))
echo "E-mail: {$_SESSION['HomeEmail']}<br />";
else {
echo "E-mail: $Required</p>";
$Missing = TRUE;
}
?>
<form action="PersonalInfo.php" method="post">
<p><input type="submit" value="Change" /></p>
</td>
<td><h2>Information about your company</a></h2>
<?php
if (isset($_SESSION['company']))
echo "Company: {$_SESSION['company']}<br />";
else {
echo "Company: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['caddress']))
echo "Address: {$_SESSION['caddress']}<br />";
else {
echo "Address: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['ccity']))
echo "City: {$_SESSION['ccity']}<br />";
else {
echo "City: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['cstate']))
echo "State: {$_SESSION['cstate']}<br />";
else {
echo "State: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['czip']))
echo "Zip: {$_SESSION['czip']}<br />";
else {
echo "Zip: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['cphone']))
echo "Phone: {$_SESSION['cphone']}<br />";
else {
echo "Phone: $Required<br />";
$Missing = TRUE;
}
if (isset($_SESSION['cemail']))
   echo "Email: {$_SESSION['cemail']}<br />";
else {  
 echo "Email: $Required<br />"; 
   $Missing = TRUE; 
}
?>
<form action="EmployerInfo.php" method="post">
<p><input type="submit" value="Change"/></p>

</td>
<td><h2>Registered Events</a></h2>
<?php
if ($_SESSION['HTML5_camp'] == TRUE)
echo "HTML5 training camp: Registered<br />";
else
echo "HTML5 camp: Not registered<br />";
/*if($_POST['html5Seminar'] == "on")
  echo "HTML5 training camp: Registered<br />";
else
  echo "HTML5 training camp: Not Registered<br />";*/
if ($_SESSION['phyton_camp'] == TRUE)
echo "Phyton training camp: Registered<br />";
else
echo "Phyton training camp: Not registered<br />";
if ($_SESSION['ruby_camp'] == TRUE)
echo "Ruby on Rails training camp: Registered<br />";
else
echo "Ruby on Rails training camp: Not registered<br />";
if ($_SESSION['perl_camp'] == TRUE)
echo "Perl training camp: Registered<br />";
else
echo "Perl training camp: Not registered<br />";
if ($_SESSION['glassfish_camp'] == TRUE)
echo "GlassFish training camp: Registered</p>";
else
echo "GlassFish training camp: Not registered</p>";
?>
</td></tr></table>
<?php
if ($Missing)
echo "<p><span style='color:red'><b>Your request cannot be registered for this event until you fill out <u><b>ALL REQUIRED</b></u> fields!</b></span></p>";
else
echo "<form action='RegisterUser.php' method='post'>
<p><input type='submit' value='Register'/></p></form>";
?>

</body>
</html>

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

Sorry it was a wrong code....))

<?php
session_start();
if (!isset($_SESSION['FirstName']) ||
!isset($_SESSION['LastName']) ||
!isset($_SESSION['HomeAddress']) ||
!isset($_SESSION['HomeCity']) ||
!isset($_SESSION['HomeState']) ||
!isset($_SESSION['HomeZip']) ||
!isset($_SESSION['HomePhone']) ||
!isset($_SESSION['HomeEmail'])||
!isset($_SESSION['company'])||
!isset($_SESSION['caddress'])||
!isset($_SESSION['ccity'])||
!isset($_SESSION['cczip'])||
!isset($_SESSION['cphone'])||
!isset($_SESSION['HTML5_camp'])||
!isset($_SESSION['phyton_camp'])||
!isset($_SESSION['perl_camp'])||
!isset($_SESSION['glassfish_camp']))
header("location:AtendeeReview.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Conference</title>
</head>
<body>
<h1>Conference 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 SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, firstName VARCHAR(40), lastName VARCHAR(40), homeaddress VARCHAR(40), homecity VARCHAR(40), homestate VARCHAR(2), homezip VARCHAR(10), homephone VARCHAR(40), homeemail VARCHAR(40), comapny VARCHAR(50), companyaddress VARCHAR(40), companystate VARCHAR(2), comapnyzip VARCHAR (10),  companyphone VARCHAR(40),  trainingsessions 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['FirstName']}' && lastName='{$_SESSION['LastName']}'";
$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 name is already registered for the conference!</p>
	<form action='PersonalInfo.php' method='post'>
	<p><input type='submit' value='Back' /></p>
	</form>");
$FirstName = addslashes($_SESSION['FirstName']);
$LastName = addslashes($_SESSION['LastName']);
$HAddress = addslashes($_SESSION['HomeAddress']);
$HCity = addslashes($_SESSION['HomeCity']);
$HState = addslashes($_SESSION['HomeState']);
$HZip = addslashes($_SESSION['HomeZip']);
$HPhone = addslashes($_SESSION['HomePhone']);
$HEmail = addslashes($_SESSION['HomeEmail']);

$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 for the conference.</p>

<h3>Thank you!!!</h3>
</body>
</html>

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.