Click to See Complete Forum and Search --> : isset not working correctly
bp_travis
08-02-2007, 02:03 PM
Hello there. I have an if statement that checks if a variable in a url is set to process a form to a database. I can't get the if statement to execute, and it doesn't return any errors. Thanks.
echo "<a href=\"new_reg_form.php?do=3\">Here!</a>";
if (isset($_GET['do'])){
$reg_id=$name. $phone;
$sql="INSERT INTO new_reg_form VALUES('$reg_id','$name','$address','$phone')";
mysql_query($sql,$db);
echo "Processed!";
foreach ($package as $insert){
$insert_p="INSERT INTO reg_packages VALUES('$reg_id','$insert')";
mysql_query($insert_p,$db);
}
}
ellisgl
08-02-2007, 02:09 PM
To test..
if (isset($_GET['do']))
{
echo 'yes';
}
else
{
echo 'no';
}
or change it to if($_GET['do'] != '')
Detect
08-02-2007, 02:15 PM
!empty($_GET['do'])
bp_travis
08-02-2007, 03:10 PM
Hello. Thanks for the replies. It displays 'no' when I insert that if statement and !empty($_GET['do'])) does not work. Basically, the echo "<a href=\"new_reg_form.php?do=3\">Here!</a>"; is a final submit button to a registration that when the user clicks the link, it inserts all the info it has gathering into a database. The whole form is one page. The blank form, validation and processing are all done on the same page. I think it could be that the if statement is not Getting the variable when I click link. Any thoughts? Thanks.
ellisgl
08-02-2007, 03:14 PM
echo '<pre>';
print_r($_GET);
echo '</pre>';
That will output the $_GET array
Detect
08-02-2007, 03:20 PM
$_request
Detect
08-02-2007, 03:21 PM
$http_get_vars
bp_travis
08-02-2007, 04:07 PM
Well, I figured out why it won't execute. Its because when they click the link it does not $_POST. That snippet of code I showed you was part of a larger if statement that only executes if($_POST). The problem is when I take it out of the larger if statement, is that all the variables in the sql statement get lost because they are in the if($_POST) statement and therefore don't initialize because the link does not $_POST. Now we have a semi-larger problem. Any suggestions? Thanks. Here is the generated page: http://www.off-lead.com/new_site/new_reg_form.php
Detect
08-03-2007, 09:58 AM
ya, just put everything in a form with action to itself method is post, input type=hidden name=do value=3, and change $_GET to $_POST or $_REQUEST
bp_travis
08-03-2007, 03:15 PM
Thanks everybody. I finally got the form working. Now, another question. Throughout the form there are multiple submits by the user (initial selection, validation, and the final submit) I used hidden fields to pass the variables among the submits to keep the same info from the first submit like a person's name. Is there a way to use sessions to permanently keep a $_POST variable for later submission no matter how many Post's come in between it and the database submission? Thanks.
Detect
08-03-2007, 03:24 PM
ya, $_SESSION["blah"] = "whatev";
just make sure you have a session_start(); at the top before anything is printed out
bp_travis
08-03-2007, 03:54 PM
Just to be sure I am clear on this, if I were to write this in PHP
$package=$_POST['Package'];
$packages=$_SESSION['packages']=$package;
the $package variable would stay the same no matter how many times a user submits the form? An example would be if the validation failed, then they would have to resubmit a different form with just the information needed, would the $package variable be carried over from the original form?Thanks