Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Okay, I have looked high and low and can't seem to find anything QUITE like this. I have found pieces but am unable to get them to work together.

Page 1: User Inputs Form Data Page 2: User Confirms Data (PHP Sessions called "FullName" & "FieldInfo" start) Page 3: Information is inserted into MySQL DB and Session "FieldInfo" is destroyed. ALSO on Page 3 there is HTML code that displays a disclaimer, at the bottom of that disclaimer I have a text field with the name "FullNameSign". This is going to act as a "Signature" field for the person to temporarily "sign" this disclaimer (until it can be mailed to them). Now, here is where my problem begins. I want a script to redirect IF $_SESSION['FullName'] equals FullNameSign Redirect to Page4.php, Else have a message saying, "Sign the form field"

Basically, it is doing NOTHING. It literally just sits there and does nothing, no error, no fail, no nothing! Ok, I don't really want to post my code because I am a noob to PHP and I know that I am probably going overboard with stuff or don't need to do some of the stuff, so don't bust me up too bad ;-) I have only been doing PHP for like a week lol, that being said, here's the code:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../Styles/Styles.css">
<link rel="stylesheet" href="../Styles/jQStyles.css">
<script src="../Scripts/Styles.js"></script>
<script src="../Scripts/jquery-ui.js"></script>
<script src="../Scripts/StateComplete.js"></script>
<script src="../Scripts/datepick.js"></script>
<script src="../Scripts/SelectorYN.js"></script>
<script>
var FullNameTest = <?php echo $_SESSION['FullNameTest'];?>
function Accept()
if (FullNameTest = FullNameSign) {
window.location.href = 'page4.php';
} else {
greeting = "Please Sign";
}
</script>
<?php

//Session
session_start(NameInfo);
session_start(FormInfo);
$Today = date("m d Y");

// Table Information
$dbhost = 'xxxx';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$dbname = 'xxxx';


// Make Connection
$con=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

// Check Connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Create table
$sql="CREATE TABLE Applicants(
Userid INT NOT NULL AUTO_INCREMENT,
FName VARCHAR(30) NOT NULL,
MName VARCHAR(30) NOT NULL,
LName VARCHAR(30) NOT NULL,
Street1 VARCHAR(30) NOT NULL,
Street2 VARCHAR(30) NOT NULL,
City VARCHAR(30) NOT NULL,
State VARCHAR(30) NOT NULL,
Zip VARCHAR(30) NOT NULL,
Gender VARCHAR(30) NOT NULL,
DOB VARCHAR(30) NOT NULL,
Email VARCHAR(30) NOT NULL,
PriPh VARCHAR(30) NOT NULL,
SecPh VARCHAR(30) NOT NULL,
PPYN VARCHAR(30) NOT NULL,
PPN VARCHAR(30) NOT NULL,
PPED VARCHAR(30) NOT NULL,
PPAD VARCHAR(30) NOT NULL,
Emp VARCHAR(30) NOT NULL,
Occ VARCHAR(30) NOT NULL,
EMName VARCHAR(30) NOT NULL,
EMRel VARCHAR(30) NOT NULL,
EMPriPh VARCHAR(30) NOT NULL,
EMSecPh VARCHAR(30) NOT NULL,
EMStrt1 VARCHAR(30) NOT NULL,
EMStrt2 VARCHAR(30) NOT NULL,
EMCity VARCHAR(30) NOT NULL,
EMState VARCHAR(30) NOT NULL,
EMZip VARCHAR(30) NOT NULL,
EMEmail VARCHAR(30) NOT NULL,
PRIMARY KEY(Userid)
)";

// Create Table If it doesn't exist
if (mysqli_query($con,$sql)) {
echo "Table created successfully";
}

// Escape Variables
$FName = mysqli_real_escape_string($con, $_SESSION['FName']);
$MName = mysqli_real_escape_string($con, $_SESSION['MName']);
$LName = mysqli_real_escape_string($con, $_SESSION['LName']);
$Street1 = mysqli_real_escape_string($con, $_SESSION['Street1']);
$Street2 = mysqli_real_escape_string($con, $_SESSION['Street2']);
$City = mysqli_real_escape_string($con, $_SESSION['City']);
$State = mysqli_real_escape_string($con, $_SESSION['State']);
$Zip = mysqli_real_escape_string($con, $_SESSION['Zip']);
$Gender = mysqli_real_escape_string($con, $_SESSION['Gender']);
$DOB = mysqli_real_escape_string($con, $_SESSION['DOB']);
$Email = mysqli_real_escape_string($con, $_SESSION['Email']);
$PriPh = mysqli_real_escape_string($con, $_SESSION['PriPh']);
$SecPh = mysqli_real_escape_string($con, $_SESSION['SecPh']);
$PPYN = mysqli_real_escape_string($con, $_SESSION['PPYN']);
$PPN = mysqli_real_escape_string($con, $_SESSION['PPN']);
$PPED = mysqli_real_escape_string($con, $_SESSION['PPED']);
$PPAD = mysqli_real_escape_string($con, $_SESSION['PPAD']);
$Emp = mysqli_real_escape_string($con, $_SESSION['Emp']);
$Occ = mysqli_real_escape_string($con, $_SESSION['Occ']);
$EMName = mysqli_real_escape_string($con, $_SESSION['EMName']);
$EMRel = mysqli_real_escape_string($con, $_SESSION['EMRel']);
$EMPriPh = mysqli_real_escape_string($con, $_SESSION['EMPriPh']);
$EMSecPh = mysqli_real_escape_string($con, $_SESSION['EMSecPh']);
$EMStrt1 = mysqli_real_escape_string($con, $_SESSION['EMStrt1']);
$EMStrt2 = mysqli_real_escape_string($con, $_SESSION['EMStrt2']);
$EMCity = mysqli_real_escape_string($con, $_SESSION['EMCity']);
$EMState = mysqli_real_escape_string($con, $_SESSION['EMState']);
$EMZip = mysqli_real_escape_string($con, $_SESSION['EMZip']);
$EMEmail = mysqli_real_escape_string($con, $_SESSION['EMEmail']);

// Insert Form Fields into MySQL
$sql="INSERT INTO Applicants (FName, MName, LName, Street1, Street2, City, State, Zip, Gender, DOB, Email, PriPh, SecPh, PPYN, PPED, PPAD, Emp, Occ, EMName, EMRel, EMPriPh, EMSecPh, EMStrt1, EMStrt2, EMCity, EMState, EMZip, EMEmail)
VALUES ('$FName','$MName','$LName','$Street1','$Street2','$City','$State','$Zip','$Gender','$DOB','$Email','$PriPh','$SecPh','$PPYN','$PPED','$PPAD','$Emp','$Occ','$EMName','$EMRel','$EMPriPh','$EMSecPh','$EMStrt1','$EMStrt2','$EMCity','$EMState','$EMZip','$EMEmail')";

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "Success";

//Close Connection
mysqli_close($con);

//Destroy FormInfo Session
session_destroy(FormInfo);
?>
<title>SALT, Inc. Mission Application Personal Information</title>
</head>
<body id="application">
<div id="divheader">
<div class="header1">
<img src="/Images/Logo.jpg" align="left" style="padding-left: 150px">
</div>
<div class="header2">

</div>
</div>
<br>
<div id="head-nav">
<ul id="nav-list">
<li id="active">
<a href="" id="homenav">Home</a>
</li>
<li>
<a href="" id="aboutnav">About Us</a>
</li>
<li>
<a href="" id="contactnav">Contact</a>
</li>
<li>
<a href="" id="applicationnav">Become A Missionary</a>
</li>
<li>
<a href="" id="projectnav">Projects</a>
</li>
<li>
<a href="" id="donatenav">Donations</a>
</li>
<li>    
<a href="" id="linksnav">Links</a>
</li>
</ul>
</div>
<br>
<div align="center" id="headertext">
<b>Short Term Mission Application</b></div>
<br>
<div style="padding-left: 20px">
<center><b>MEDICAL RELEASE</b><br><br>
*Disclaimer is contained here*
Applicant’s signature: <form><input type="text" name="FullNameSign"><br><br>
Date: <?php echo $Today;?><br><br>
<input type="button" onClick="Accept()" value="Next"></form>
</body>
</html>

Thanks, in advance, for any help

share|improve this question
    
It would probably help to start with valid PHP. No idea why you're doing session_start twice in a row, and session_start(NameInfo) isn't PHP - it'd either be session_start($NameInfo) or session_start('NameInfo'), but session_start doesn't even take any parameters at all. Where are you learning this syntax? –  ceejayoz May 16 at 1:07
    
I have 2 session starts because I have one session that keeps all the info from the Form 2 pages back and the other takes the users First Middle and Last Name and makes it their Full Name. That I want to carry across like 4 more pages. I didn't realize that was how they needed named, I figured it was like naming a function, it is however, working. Like when I call on FullName down in the disclaimer, it will display what I tell it to. I will fix that though –  S1naps1s May 16 at 1:14
2  
If this is your first week of PHP, maybe start with something simpler. I don't think you understand sessions, for one thing, or how CGI variables work. Write a page that takes one parameter and prints Hello <name>. Then make it more complex. Don't try to do everything at once. Test as you go. –  Hamza Kubba May 16 at 1:16
1  
To expand on what @ceejayoz said, you only need to call session_start() once at the top of your page. To save session information you would use $_SESSION['NameInfo'] = 'John Doe'; or whatever you're trying to save. Then you can recall that information by using just $_SESSION['NameInfo'] which in this case would give you John Doe –  Tomjr260 May 16 at 1:22
1  
PHP can only have one session going at a time, and you don't need to name it. Passing a parameter to session_start is completely useless. The names come in at the $_SESSION['name'] part. So only one session_start(), and no parameters. Using session_destroy() will delete ALL of your session data that you set on this page. If you want to delete specific $_SESSION[] info, use unset($_SESSION['name']); –  Tomjr260 May 16 at 1:34

1 Answer 1

Here are some highlites of some other problems. BTW: http://www.php.net/function.session-start will tell you everything you want to know about session_start(); and http://www.php.net/manual/en/function.session-destroy.php will tell you everything you want to know about session_destroy();

In your lines like: $FName = mysqli_real_escape_string($con, $_SESSION['FName']); Perhaps I missed it, but the setting of that session variable seems to be missing And before using a session (or post or get) variable, a check should be performed to assure that variable is actually set and contains some value. This can be done like this: if( isset($_SESSION['FName']) && false != $_SESSION['FName'] ) { $FName = mysqli_real_escape_string( $con, $_SESSION['FName'] ); } else { $FName = 'dummy value'; // set some reasonable value, so the query does not cause a crash in the DB query } This kind of existence checking should be done for each of the session variables.

I notice the variable $Today is being accessed, but I do not see where it is being set. The following will tell you all you need to know about obtaining a date value http://php.net/manual/en/function.date.php

If you run your code through some syntax checker, like tidy http://tidy.sourceforge.net/ most of the syntax, html tag pairing, and similar such opps will be remarked upon, to make them easy to spot/correct.

Please apply the above information, then edit the code. Then we can assist you with the basic problem that you want answered.
Most importantly, please clarify the explanation of what you want the code to do. Without such clarification, I/we have only a vague idea as to which way to direct you in fixing the code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.