Variables go poof...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Variables go poof...

Post by Steveo31 »

Sup-

Have a little issue with variables passed from one if() statement to the other. The situation here is that the user can sign up for an appointment, and then once it is submitted, the URL changes and it is then dealt with from there, based on the GET vars.

Up to this point it works ok. Here's the code:

Code: Select all

<?php
if(isset($_GET['status'])){
if($_GET['status']=='addlesson'){
$date = '2004-'.$_POST['month'].'-'.$_POST['day'];
$stime = $_POST['hour'].':'.$_POST['minute'];
$etime = $_POST['ehour'].':'.$_POST['eminute'];

?>


<table width="50%">
//all the above variables are successfully echoed.
</table>


<?php
}//end status
}else{ //end if GET == status
?>
<form action="members.php?action=setappt&status=addlesson" method="post">
//form stuff
</form>
So once the user submits that form, the url goes to members.php?action=setappt&status=addlesson. That just shows the data, letting the user see what they entered, and from there can make changes or confirm.

To confirm, I have a hyperlink:

<a href="members.php?action=setappt&status=addlesson&valid=1>Click if Okay</a>

Now, I can't get it to recognize the variables are still there once that link is clicked. The page stays there, but the echoed variables disappear, and 0000-00-00 is entered in the database.

I've tried

Code: Select all

if(isset($_GET['valid'])){
    if($_GET['valid'] == '1'){
        echo "DATE:  ".$date;
    }
}
Above the initial if(isset($_GET['status'])), but the variables are empty.

....
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try this:

Code: Select all

<?php 
if(isset($_POST['status'])){ 
if($_POST['status']=='addlesson'){ 
$date = '2004-'.$_POST['month'].'-'.$_POST['day']; 
$stime = $_POST['hour'].':'.$_POST['minute']; 
$etime = $_POST['ehour'].':'.$_POST['eminute']; 

<table width="50%"> 
//all the above variables are successfully echoed. 
</table> 


<?php 
}//end status 
}else{ //end if GET == status 

<form action="members.php" method="post"> 
<input type="hidden" name="setappt" value="addlesson">
<input type="hidden" name="status"  value="addlesson">
//form stuff 
</form>
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

For some reason that makes a textbox... weird. But no, that wasn't it. ARGH!!
Post Reply