Forum Moderators: coopster
why wont this work?
scenario 1: assign session variables from a POST..
session_start();
$_SESSION['sessdateref'] = $_POST['dateref'];
$_SESSION['sessnoguests'] = $_POST['noguests'];
$_SESSION['sessguests'] = $_POST['guests'];
nothing works...
Scenario 2: Assign POST to variables then to SESSION
$noguests = trim ($_POST['noguests']);
$guests = trim ($_POST['guests']);
$date = trim ($_POST['dateref']);
session_start();
$_SESSION['sessdateref'] = $date;
$_SESSION['sessnoguests'] = $noguests;
$_SESSION['sessguests'] = $noguests;
nothing works...
Scenario 3: try a set string or number and not a variable
session_start();
$_SESSION['sessdateref'] = "why?";
$_SESSION['sessnoguests'] = $noguests;
$_SESSION['sessguests'] = 13;
output from : why? 13 (ie. no variable between)
to summarise:
= '$noguests'; gives me why? $noguests 13
= "$noguests"; gives me why? 13
= $noguests gives me why? 13
= $_POST['noguests']; gives me why? 13
the string "why?" always works
the number 13 always works
The single quoted 'strings' work
any $variable or $_POST wont work
the variables assigned from the POST print on the screen
if thats a bit muddled looking then im sorry i can give more details if you like
Please help!
Derek
error_reporting(E_ALL); to the top of the script. Also, use $HTTP_SESSION_VARS with PHP 4.0.6 or less(instead of $_SESSION). Good luck!
2) To initiate a session from the same file:
$_SESSION['sessguests']=$sessguessts;
$sessguessts=$_SESSION['sessguests'];
//echo "test guests $sessguest";
3) to use it anywhere:
session_start();
$sessguessts=$_SESSION['sessguests'];
[url=http://us2.php.net/manual/en/function.print-r.php]print_r[/url]($_POST);//prints out the _POST array
If the values are actually set correctly, then they should show here. For additional debugging add error_reporting [us2.php.net](E_ALL); to the top of the script. Make sure all of your spelling is correct too ;)
Good luck!
ehh..to not waste a post. PHP should be enabled because the session was set to a string value and echoed out correctly without error ;)
a form filled in gets posted to the second page
the second page creates session cookies (supposedly), checks fields are filled in correctly or not, displays the forms contents for verification and has a submit button, which inserts the forms info into a record in mysql, and goes to the third page
the third page accesses the session cookies.
THE CODE FOR THE SECOND PAGE
<?php session_start();
$_SESSION['sessdateref'] = "why?";
$_SESSION['noguests'] = trim ($_POST['noguests']);
$_SESSION['sessguests'] = 7;
//get form info
$firstname= trim ($_POST['firstname']);
$lastname= trim ($_POST['lastname']);
$add1= trim ($_POST['add1']);
$add2= trim ($_POST['add2']);
$add3= trim ($_POST['add3']);
$city= trim ($_POST['city']);
$postcode = trim ($_POST['postcode']);
$country= trim ($_POST['country']);
$telephone= trim ($_POST['telephone']);
$email= trim ($_POST['email']);
$noguests = trim ($_POST['noguests']);
$guests = trim ($_POST['guests']);
$date = trim ($_POST['dateref']);
require_once('Connections/local_connection.php');
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc())? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue!= "")? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue!= "")? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue!= "")? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue!= "")? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue!= "")? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO bookers (bookerfirstname, bookerlastname, bookeradd1, bookeradd2, bookeradd3, bookercity, bookerpostcode, bookercountry, bookertelephone, bookeremail, noguests, bookerguests) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['1st'], "text"),
GetSQLValueString($HTTP_POST_VARS['2nd'], "text"),
GetSQLValueString($HTTP_POST_VARS['ad1'], "text"),
GetSQLValueString($HTTP_POST_VARS['ad2'], "text"),
GetSQLValueString($HTTP_POST_VARS['ad3'], "text"),
GetSQLValueString($HTTP_POST_VARS['cit'], "text"),
GetSQLValueString($HTTP_POST_VARS['postc'], "text"),
GetSQLValueString($HTTP_POST_VARS['coun'], "text"),
GetSQLValueString($HTTP_POST_VARS['telph'], "text"),
GetSQLValueString($HTTP_POST_VARS['ema'], "text"),
GetSQLValueString($HTTP_POST_VARS['nog'], "int"),
GetSQLValueString($HTTP_POST_VARS['gsts'], "text"));
mysql_select_db($database_local_connection, $local_connection);
$Result1 = mysql_query($insertSQL, $local_connection) or die(mysql_error());
$insertGoTo = "choosehow2pay.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?'))? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}?>
the actual body of the page is an if statement (if fields are empty, make user go back)(else make a form, show the values of the variables, and submit inserts to mysql then goes to the third page)
THE THIRD PAGES CODE
<?php session_start();
$noguests = $_SESSION['sessnoguests'];
$guests = $_SESSION['sessguests'];
$dateref = $_SESSION['sessdateref'];
?>
...and later...
<?php
print "<p>$dateref $noguests $guests</p>";
?>
it must be the dreamweaver method because i managed to make a form go to a blank page then a third page and display the contents but it doesnt seem to be doing it here
could it be anything to do with the fact that there is an insert to mysql on this page?
I told you it may be in the spelling ;)
I just tried the same thing on another site with the same result.
I think it has something to do with the fact that the second page creates the session variables but then does a dreamweaver record update
when i get to the third page the url has a? on the end with no data after it
its almost as if it thinks it is a new session or something
Any ideas?
?PHPSESSID3486rvb8tioygargibberish
this definitely has something to do with it then
but how do we get round that? i take it we are all better off hand coding then instead of relying on dreamweavers method or have i stumbled across a limitation of php or mysql? i dunno please help, getting desperate here!