Variable doesn't hold the value

+1 TJ Le · August 1, 2014
Hi everyone. I seem to have this problem where I would have my variable set to a value, and then all of a sudden when i call the variable, it will not bring up my value. I'm pretty new at this, and it is driving me crazy! Any thoughts on this? I know this is probably easy and maybe I could not spot this myself.

<html>
<div id = "insidebox1">
<title>Registration Form </title>
<form method = "get" action = "reg2.php">
<h1>Registration Form</h1>
<h2>Please fill out the following,</h2>
<p>Title* : <input type="text" name="title" size="6" maxlength="6" value=""/></p>
<p>First Name* : <input type="text" name="fname" size="15" maxlength="20" value=""/></p>
<p>Middle Name : <input type="text" name="mname" size="15" maxlegnth="20" value=""/></p>
<p>Last Name* : <input type="text" name="lname" size="15" maxlength="20" value=""/></p>
<p>Occupation* : <input type="text" name="occ" size="35" maxlength="45" value=""/></p>
<p>Address* : <input type="text" name="add" size="35" maxlength="45" value=""/></p>
<p>Email* : <input type="text" name="email" size="25" maxlength="35" value=""/></p>
<p>City* : <input type="text" name="city" size="17" maxlength="25" value=""/></p>
<p>Province/State* : <input type="text" name="state" size="15" maxlength="23" value=""/></p>
<p>Country* : <input type="text" name="count" size="19" maxlength="25" value=""/></p>
<p>Postal/ZIP Code* : <input type="text" name="code1" size="8" maxlength="10" value=""/></p>
<p><input type="submit" name ="submit" value="Register"?></p>

<body>* = Required Fields.</body>
</form>
</div>
</html>

My registration form. 

<html>
<title>Overview</title>
<body>
<p><b>PLEASE READ OVER THE FOLLOWING</p><i>
Your title is:<strong> <?php echo $_GET["title"]; ?><br>
Your first name is: <?php echo $_GET['fname']; ?><br>
Your middle name is: <?php echo $_GET['mname']; ?><br>
Your last name is: <?php echo $_GET['lname']; ?><br>
Your occupation is: <?php echo $_GET['occ']; ?><br>
Your area of residence is: <?php echo $_GET['add']; ?><br>
Your email is: <?php echo $_GET['email']; ?><br>
You live in: <?php echo $_GET['city']; ?><br>
In the province/state of: <?php echo $_GET['state']; ?><br>
In the country of: <?php echo $_GET['count']; ?><br>
Your Postal/ZIP code is: <?php echo $_GET['code1']; ?><br>
<br>
<br>
<?php echo $_GET['title'];?>
<?php echo $_GET['title'];?>
<p>IS THE INFORMATION LISTED ABOVE CORRECT?</p>
<a href="confirmanswers.php">Yes, it is correct.</a>
<br>
<br>
<p>If no, please press the back button to make any changes.</p>
</body>
</html>
This is the file that I want the first file to go after getting all the input from the user. File name reg2.php

<?php
include('connect.php')or die('mysql error');
$title=$_GET['title']or die('you dun goofed');
$fname=$_GET['fname'];
$mname=$_GET['mname'];
$lname=$_GET['lname'];
$occ=$_GET['occ'];
$add=$_GET['add'];
$email=$_GET['email'];
$city=$_GET['city'];
$state=$_GET['state'];
$count=$_GET['count'];
$code1=$_GET['code1'];
echo 'hello';
mysql_query("INSERT INTO temp(Title,FirstName,MiddleName,LastName,Occupation,Address,Email,City,State,Country,Code)VALUES('$title','$fname','$mname',$
echo 'An email has been sent to you for verification.';
echo '<a href="register.html">Click here to be redirected to the registration page</a>';
?>

This is the file I want the second file to go to after it finishes processing. File name confirmanswers.php
Here is where I get the problem. At the part where it says $title=$_GET['title']or die('you dun goofed'); , it dies on me. I was sure that the variable still held the value inside it, but now I am lost on what happened and what to do.
Help out the rookie here!
Thanks.

Post a Reply

Replies

Oldest  Newest  Rating
0 TJ Le · August 6, 2014
Great. Looks like it is working with the code you presented Franz.
+1 Franz Schmidt · August 6, 2014
If you make another submit button you also need a form to post. That means you also need input tags.
There is a posibility to make input boxes, where you don't have to enter values:

<form method="GET" action="confirmanswer.php">
   <input type="hidden" name="title" value=$_GET['title']/>    //this line is a hidden input so if you send your form this will be a $_GET variable on your next page.
   
   <input type="submit" value="Yes, it is correct">
</form>

But i really recommend to you sessions or cookies it's much easier.
0 TJ Le · August 5, 2014
Alright, I changed the link confirmanswer.php to a simple submit button, and created form tags with the method get and action confirmanswer.php. Problem is, it is still terminating at the same spot. Here is where I added the changes.
 
<html>
<title>Overview</title>
<body>
<p><b>PLEASE READ OVER THE FOLLOWING</p><i>
Your title is:<strong> <?php echo $_GET["title"]; ?><br>
Your first name is: <?php echo $_GET['fname']; ?><br>
Your middle name is: <?php echo $_GET['mname']; ?><br>
Your last name is: <?php echo $_GET['lname']; ?><br>
Your occupation is: <?php echo $_GET['occ']; ?><br>
Your area of residence is: <?php echo $_GET['add']; ?><br>
Your email is: <?php echo $_GET['email']; ?><br>
You live in: <?php echo $_GET['city']; ?><br>
In the province/state of: <?php echo $_GET['state']; ?><br>
In the country of: <?php echo $_GET['count']; ?><br>
Your Postal/ZIP code is: <?php echo $_GET['code1']; ?><br>
<br>
<br>
<?php echo $_GET['title'];?>
<?php echo $_GET['title'];?>
<p>IS THE INFORMATION LISTED ABOVE CORRECT?</p>
<form method="get" action="confirmanswer.php">
<input type="submit" value="Yes, it is correct">
</form>

<br>
<br>
<p>If no, please press the back button to make any changes.</p>
</body>
</html>

In bold is where to change is. Is this the correct way of doing this? From my understanding of form, I don't see where it would make more sense, but hey, what do I know right? As for cookies and sessions, I have cookies already running on the page and I have added <?php session_start() and session_destroy() ?> to my files.
0 TJ Le · August 2, 2014
Ok Franz, I will try that out and see if that works. 
+1 Jonah Morrison · August 2, 2014
Franz is right! Didn't see that yesterday. Must of been tired lol.
+2 Franz Schmidt · August 2, 2014
Your problem is that you just have a link at the reg2.php to the confirmanswer.php file. If you only have a link there won't be any get or post variables.
In order to use those variables also on the confirmanswer.php file you could use another form in the reg2.php to transfer them.
Or the better way you could use sessions or cookies to save the variables.
0 TJ Le · August 2, 2014
that die function was just to test where it was going wrong. i am trying to give the user two choices: confirm the user's input or go back and change theirs. Here, i want to take the user's input, query it into mysql, and its done.
0 TJ Le · August 2, 2014
I am giving the user 2 choices, either confirm or change their answers. Here, my second file has a link to the third file, which then i want the third file to execute a mysql_query on the data. 
+1 Jonah Morrison · August 1, 2014
Try this:
if(isset($_GET['title'])){
$title = $_GET['title'];
}else{
$title = 'Not Set...';
}
0 Jonah Morrison · August 1, 2014
Well you don't need a die function there. What is it you are trying to do?
  • 1

PHP

107,228 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators