PHP - Session Variables Lost When Form Posted
Hi,
I have a feeling that this is going to be an easy miss but I've been over is a good few times and cannot see what it could be. Essentially, when I post the form in the first set of code (I've got rid of a load of unecessary html) the SESSION variables are not loaded into the second piece of code. Any ideas? Code: [Select] <?php session_start(); require ("connect.php"); $timeout = 1800; $logout_redirect_url = "login.php"; if (isset($_SESSION['start_time'])) { $elapsed_time = time() - $_SESSION['start_time']; if ($elapsed_time >= $timeout) { session_destroy(); header("Location: $logout_redirect_url"); } } $_SESSION['start_time'] = time(); ?> <div id="leftlink"> <a href="logout.php">Logout</a> </div> <table align="center" width="600px" cellpadding="0" cellspacing="0"> <tr> <td> <h2 align="center"><a href="index.php"><img src="images/logo.jpg" border="0" /></a> <br /> Emergency</h2> <hr /> </td> </tr> </table> </head> <body> <form action="post_reset.php" method="post" name"passre"> <table width="500" border="0" align="center" cellpadding="2" cellspacing="1"> <tr> <td width="230"><div align="right">E-mail Address : </div></td> <td width="40"> </td> <td width="230"><div align="left"> <input name="email" readonly="readonly" value="<?php echo ($_SESSION['email']) ; ?>" /></div></td> </tr> <tr> <td colspan="3"><div align="center"><input type="submit" name="submit" value="Submit" /></div></td> </tr> </table> </form> </body> </html> Code: [Select] <?php session_start; echo ($_SESSION['start_time']); require ("connect.php"); if (isset($_POST['submit'])){ $email = $_POST['email']; $getde = "SELECT * FROM users WHERE email = '$email'"; $getder = mysql_query($getde, $conn); $getdere = mysql_fetch_array($getder) Thanks Gareth Similar TutorialsHello all, I just wrote a php website to communicate with a database and it has a login based on the users email and password, they login on the first page and then the php checks for every page they visit if they indeed logged in before and not just found out what php file to open to get where they want to be. For this I used session variables to store both e-mail and password. The login info gets posted from the 1st(login) site to the 2nd site where it is checked for the first time, after that the login info isn't posted to the next page anymore, but just checked, this works for the 3rd page but when the user hits for the 4th page the variables are lost(I can't echo them either). However if I'd go from the 2nd page directly to the 4th page the page will load, however the 5th will then get my security-msg. So offcourse, I am wondering how this might have happened and how to fix this problem, here's some of the code I wrote: This is the check for the logininfo: <?php include('SessionStart.php'); include('logindata.php'); $db = mysql_connect($host, $user, $pw); if (!$db) { echo "<br />Helaas, u heeft geen verbinding met de database."; exit(); } else { mysql_select_db("teammanagementtool", $db); $sql24 = "SELECT * FROM leidinggevenden"; $allesarray = mysql_query($sql24); $i = 0; while ($mails = mysql_fetch_array($allesarray)) { $mailtjes[$i] = $mails['lg_mailadres']; $i = $i+1; } echo "...".$_SESSION['sessie']['email']."...".$_SESSION['sessie']['password']."...".$session_name."..."; if (in_array($_SESSION['sessie']['email'],$mailtjes)) { $sql25 = "SELECT lg_wachtwoord FROM leidinggevenden WHERE lg_mailadres = '".$_SESSION['sessie']['email']."'"; $pass = mysql_query($sql25); $pasje = mysql_fetch_array($pass); if ($_SESSION['sessie']['password'] != $pasje['lg_wachtwoord']) { echo "<script>alert('U bent hier op incorrecte manier terecht gekomen!');</script>"; echo "<meta http-equiv='refresh' content='0;URL=index.php' />"; exit(); } else if ($_SESSION['sessie']['password'] = "" || $_SESSION['sessie']['email'] = ""){ echo "<script>alert('U bent hier op incorrecte manier terecht gekomen!');</script>"; echo "<meta http-equiv='refresh' content='0;URL=index.php' />"; exit(); } else { } } else { echo "<script>alert('U bent hier op incorrecte manier terechtgekomen!');</script>"; echo "<meta http-equiv='refresh' content='0;URL=index.php' />"; exit(); } ?> And this is the code in my SessionStart.php: <?php $session_name = 'sessie'; $session_exp_time = 10000 ; $previous_name = session_name($session_name); ini_set('session.gc_maxlifetime', $session_exp_time); ini_set('session.gc_probability', '1'); ini_set('session.gc_divisor', '1000'); ini_set('session.name', $session_name); ini_set('session.cookie_domain', ''); ini_set('session.cookie_lifetime', 0 ); session_set_cookie_params($session_exp_time, '/', ''); session_start(); if (isset($_COOKIE[$session_name])) setcookie($session_name, $_COOKIE[$session_name], 2147483647 , ''); ?> the includes are at the start of all of my pages, I only do a session_unset() at my index.php(the login page). and my 2nd page gets: $_SESSION['sessie']['email'] = $_POST['email']; $_SESSION['sessie']['password'] = $_POST['password']; from the login. I could really use some help here, thanks in advance. I need some help displaying the posted values onto a second page. I thought I was doing it right, but nothing is showing up on my second page. I have my form set to PHP_SELF to validate before sending the user to the second page, and it's working just fine. If no errors are present, the user is redirected to the second page, but it's supposed to be displaying their posted data, but it's not. What am I doing wrong? Code: [Select] <?php /*$name = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $phone = ""; $position = ""; $display_errors = "";*/ if (@$_POST['submitted']){ $name = (@$_POST['name']); $address = (@$_POST['address']); $city = (@$_POST['city']); $state = (@$_POST['state']); $zip = (@$_POST['zip']); $phone = (@$_POST['phone']); $position = (@$_POST['position']); if (get_magic_quotes_gpc()){ $name = stripslashes($name); $address = stripslashes($address); $city = stripslashes($city); $state = stripslashes($state); $zip = stripslashes($zip); $phone = stripslashes($phone); $position = stripslashes($position); } $error_msg=array(); if ($name==""){ $error_msg[]="Please enter your name"; } if ($address==""){ $error_msg[]="Please enter your address"; } if ($city==""){ $error_msg[]="Please enter your city"; } if ($state==""){ $error_msg[]="Please enter your state"; } if ($zip==""){ $error_msg[]="Please enter your zip code"; } if ($phone==""){ $error_msg[]="Please enter your phone number"; } if ($position==""){ $error_msg[]="Please enter your desired position"; } if ($error_msg){ $display_errors = "<ul style=color:red>\n"; foreach ($error_msg as $err){ $display_errors .= "<li>".$err."</li>\n"; } $display_errors .= "</ul>\n"; } if (!$error_msg){ //echo $name . "<br>"; //echo $address . "<br>"; //echo $city . "<br>"; //echo $state . "<br>"; header('Location: process_U2IP.php'); exit(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Forms1.php</title> </head> <body> <div id="content"> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <h3>Please fill out the form below and upload your resume to apply for a position within our company:</h3> <label for="name">Name*</label><br /> <input name="name" type="text" size="20" id="name" value="<?php echo $name; ?>" /><br /> <label for="address">Address*</label><br /> <input name="address" type="text" size="20" id="address" value="<?php echo $address; ?>" /><br /> <label for="city">City*</label><br /> <input name="city" type="text" size="20" id="city" value="<?php echo $city; ?>" /><br /> <label for="state">State*</label><br /> <input name="state" type="text" size="20" id="state" value="<?php echo $state; ?>" /><br /> <label for="zip">Zip*</label><br /> <input name="zip" type="text" size="20" id="zip" value="<?php echo $zip; ?>" /><br /> <label for="phone">Phone*</label><br /> <input name="phone" type="text" size="20" id="phone" value="<?php echo $phone; ?>" /><br /> <label for="position">Position*</label><br /> <input name="position" type="text" size="20" id="position" value="<?php echo $position; ?>" /><br /> <p><i>Your information will not be sold or shared with others.</i></p> <p style="color: red;">* denotes required field</p> <input type="hidden" name="submitted" value="1" /> <input type="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> <?php echo $display_errors; ?> </div> </body> </html> Code: [Select] <?php $name = (@$_POST['name']); $address = (@$_POST['address']); $city = (@$_POST['city']); $state = (@$_POST['state']); $zip = (@$_POST['zip']); $phone = (@$_POST['phone']); $position = (@$_POST['position']); $display_block = " <table> <tr> <td><b>Name:</b></td> <td>$name</td> </tr> <tr> <td><b>Address:</b></td> <td>$address</td> </tr> <tr> <td><b>City:</b></td> <td>$city</td> </tr> <tr> <td><b>State:</b></td> </tr> </table>"; echo $display_block; ?> It's just displaying the table but with no values or blank values for the posted variables. Can anyone help? Hi all I have a php form as follows: <form action="basket.php?action=add&id=1&qty=1" method="post" name="buy-product"> <input name="initial_1" id="initial_1" type="text" size="8" maxlength="1" /> <input name="initial_2" id="initial_2" type="text" size="8" maxlength="1" /> <input name="initial_3" id="initial_3" type="text" size="8" maxlength="1" /> <input name="send" type="submit" class="contact-form-button" id="send" value="Submit" /> Basically I need to add the three initials into a session so that they can be shown in the shopping cart next to the product. How do I add the initials to the session and how do I output them to the shopping cart? At the start of my basket.php script I have: $cart = $_SESSION['cart']; $action = $_GET['action']; $id = $_GET['id']; $qty = $_GET['qty']; $initial_1 = $_POST['initial_1']; $initial_2 = $_POST['initial_2']; $initial_3 = $_POST['initial_3']; I now need to create a table with the cart showing item, price and initials. Cheers Pete. This is a multi page registration form. I want to check the user input from form1.php with preg_match in form2.php then return the users details back into form1 with error messages(e.g $errname) so the user doesn't need to re enter the information. Neither the error messages or the session variables are shown in form1.php's form. I've echoed out the session variables found that the value makes it to form 2. But the variables are empty when it goes back to form 1. form1.php <html> <head> <title>Register</title> <style type="text/css"> td { vertical-align: top; } .errText { font-family: Arial; font-size: 10px; color: #CC0000; text-decoration: none; font-weight: normal; } </style> </head> <body> <form action="form2.php" method="post"> <table> <tr> <td><label for="name">Username:</label></td> <td><input type="text" name="name" id="name" size="20" maxlength="20" value="<?php echo $_SESSION['name'];?>"/> <?php if(isset($_POST[$errname])) echo $errname; ?></td> </tr><tr> <td><label for="password">Password:</label></td> <td><input type="password" name="password" id="password" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="first_name">First name:</label></td> <td><input type="text" name="first_name" id="first_name" size="20" maxlength="20" value="<?php echo $_SESSION['first_name'];?>"/> <?php if(isset($_POST[$errfirst])) echo $errfirst; ?></td> </tr><tr> <td><label for="last_name">Last name:</label></td> <td><input type="text" name="last_name" id="last_name" size="20" maxlength="20" value="<?php echo $_SESSION['last_name'];?>"/> <?php if(isset($_POST[$errlast])) echo $errlast; ?> </td> </tr><tr> <td><label for="email">Email:</label></td> <td><input type="text" name="email" id="email" size="20" maxlength="50" value="<?php echo $_SESSION['email'];?>"/> <?php if(isset($_POST[$erremail])) echo $erremail; ?></td> </tr><tr> <td><label for="address">Address:</label></td> <td><input type="text" name="address" id="address" size="20" maxlength="20" value="<?php echo $_SESSION['address'];?>"/> <?php if(isset($_POST[$erraddress])) echo $erraddress; ?></td> </tr><tr> <td><label for="city">City/Town:</label></td> <td><input type="text" name="city" id="city" size="20" maxlength="20" value="<?php echo $_SESSION['city'];?>"/> <?php if(isset($_POST[$errcity])) echo $errcity; ?></td> </tr><tr> <td><label for="county">County:</label></td> <td><input type="text" name="county" id="county" size="20" maxlength="20" value="<?php echo $_SESSION['county'];?>"/> <?php if(isset($_POST[$errcounty])) echo $errcounty; ?></td> </tr><tr> <td><label for="post">Postcode:</label></td> <td><input type="text" name="post" id="post" size="20" maxlength="20" value="<?php echo $_SESSION['post'];?>"/> <?php if(isset($_POST[$errpost])) echo $errpost; ?></td> </tr><tr> <td><label for="home">Home Number:</label></td> <td><input type="text" name="home" id="home" size="20" maxlength="20" value="<?php echo $_SESSION['home'];?>"/> <?php if(isset($_POST[$errhome])) echo $errhome; ?></td> </tr><tr> <td><label for="mobile">Mobile:</label></td> <td><input type="text" name="mobile" id="mobile" size="20" maxlength="20" value="<?php echo $_SESSION['mobile'];?>"/> <?php if(isset($_POST[$errmobile])) echo $errmobile; ?></td> </tr><tr> <td> </td> <td><input type="submit" name="submit" value="Sumbit"/></td> </tr> </table> </form> </body> </html> form2.php <?php //let's start the session session_start(); //finally, let's store our posted values in the session variables $_SESSION['name'] = $_POST['name']; $_SESSION['password'] = $_POST['password']; $_SESSION['first_name'] = $_POST['first_name']; $_SESSION['last_name'] = $_POST['last_name']; $_SESSION['email'] = $_POST['email']; $_SESSION['address'] = $_POST['address']; $_SESSION['city'] = $_POST['city']; $_SESSION['county'] = $_POST['county']; $_SESSION['post'] = $_POST['post']; $_SESSION['home'] = $_POST['home']; $_SESSION['mobile'] = $_POST['mobile']; $errname = ""; $errfirst = ""; $errlast = ""; $erremail = ""; $erraddress = ""; $errcity = ""; $errcounty = ""; $errpost = ""; $errhome = ""; $errmob = ""; if( preg_match('/^[A-Z][a-zA-Z -]{3,30}+$/',$_SESSION['name']) ) { $errname = '<p class="errText">Name must be from letters, dashes, spaces and must not start with dash</p>'; } if( preg_match('/^[A-Z][a-zA-Z -]{3,30}+$/',$_SESSION['first_name']) ) { $errfirst = '<p class="errText">Name must be from letters, dashes, spaces and must not start with dash</p>'; } if( preg_match('/^[A-Z][a-zA-Z -]{3,30}+$/',$_SESSION['last_name']) ) { $errlast = '<p class="errText">Name must be from letters, dashes, spaces and must not start with dash</p>'; } if( preg_match('/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/',$_SESSION['email']) ) { $erremail = '<p class="errText">This is not a valid email address.'; } if( preg_match('/^[a-zA-Z0-9 _.,:\"\']+$/',$_SESSION['address']) ) { $erraddress = '<p class="errText">Address must be only letters, numbers or one of the following ". , : /"</p>'; } if( preg_match('/[a-zA-Z]+/',$_SESSION['city']) ) { $errcity = '<p class="errText">Your city must contain a letter.'; } if( preg_match('/[a-zA-Z]+/',$_SESSION['county']) ) { $errcounty = '<p class="errText">Your county must contain a letter.'; } if( preg_match('/(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})/',$_SESSION['post']) ) { $errpost = '<p class="errText">This is not a valid UK Postcode.'; } if( preg_match('/s*\(?0\d{4}\)?(\s*|-)\d{3}(\s*|-)(\d{3}\s*)|(\s*\(?0\d{3}\)?(\s*|-)\d{3}(\s*|-)\d{4}\s*)|(\s*)(7|8)(\d{7}|\d{3}(\-|\s{1})\d{4})\s*/',$_SESSION['home']) ) { $errhome = '<p class="errText">This is not a valid UK local phone number.'; } if( preg_match('/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/',$_SESSION['mobile']) ) { $errmob = '<p class="errText">This is not a valid UK mobile phone number.'; } else{ $errname = ($_POST[$errname]); $errfirst = ($_POST[$errfirst]); $errlast = ($_POST[$errlast]); $erremail = ($_POST[$erremail]); $erraddress = ($_POST[$erraddress]); $errcity = ($_POST[$errcity]); $errcounty = ($_POST[$errcounty]); $errpost = ($_POST[$errpost]); $errhome = ($_POST[$errhome]); $errmob = ($_POST[$errmob]); header("Location: form1.php"); exit; } ?> Any help appreciated. I think I should buy a professional book, instead of my beginner one. hello everyone....i need your help i face session lost problem so many times and every times i just find out other logic to implement the code in different ways. but i don't get a perfect solution.Please help me to resolve this............why it was happened..... i searched google for it.........this is the common problem but i dont get any proper solution.............. recently i write a code to fetch tweets from twitter..but when returning back from .i lost my session value......... supp this is my page page.php when user click on button........i just check the form submitted like this session_start(); $_SESSION['id']=$id; //supp $id=10 if($_POST['submit']) { header("Location:tweet.php "); } i already included session_start() at the top of every page. in tweet.php i just generate a token and send user to twitter for authorization. in tweet.php i checked session started i check it with Print_r($_SESSION); in this page i used session like this session_start(); if($_SESSION['id']) { header("Location:$url") //$url will be authoritarian url generated by twitter oauth.. }else { header("Location:index.php") } after returning from twitter some times session variable are not lost.but sometimes i lost my session.this really irritates me....if logic is wrong then every time session destroyed............... i check my php.ini file configuration.. session_save.path=/tmp; //by default register global are off................. any help is appreciated................ Well i have a session['rmanr'] a have set after a submit containing the date and unique id.
I have to be able to do multiple submits on that same form but if they submit multiple times the same rmanr have to be used...
I tried the following:
$date = date("Y-m-d"); $datestrip = str_replace("-", "", $date); $lastdetid = $dbh->lastInsertId(); if(!isset($_SESSION['rmamr'])){ $rmanr = $datestrip; $rmanr .= $lastdetid; $_SESSION['rmanr'] = $rmanr; } else { $rmanr = $_SESSION['rmanr']; } $uprmastmt = $dbh->prepare("UPDATE rma SET r_nr = '$rmanr' WHERE r_id = ?"); $uprmastmt->bindParam(1, $lastid); $uprmastmt->execute();But i keep getting a new rmanr every time i submit... Could it be that my form submit reset my SESSION? My form Code: [Select] <form action="process.php" method="post"> <font face= "calibri" size= "4"> <table border= "1"> <tr style= "background: #cccccc"> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value=""/></td> </tr> <tr style= "background: #99ff00"> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value=""/></td> </tr> </tr style= "background: #A8E5FF"> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "winningBidder" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <br/> <input type="reset" value="Reset Form"><input type="submit" name="submit" value= "Save & Cont." " /> </form></font> My process script: Code: [Select] <?php error_reporting(E_ALL); ini_set("display_errors", 1); $host= ""; $db_name= ""; $db_user= ""; $db_password= ""; $logUser= $_POST['logUser']; $deleteBidder = $_POST['deleteBidder']; $newBidder= $_POST['newBidder']; $itemDescription= $_POST['itemDescription']; $itemPrice= $_POST['itemPrice']; $winningBidder= $_POST['winningBidder']; $itemQty= $_POST['itemQty']; ob_start(); if ($_POST['newBidder']) { $bidderId= $newBidder; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM bidders WHERE biddersId='$bidderId'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==0){ // Add $biddersId and redirect to anypage mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$bidderId')"); header("Location: index.php"); exit(); } } if ($_POST['deleteBidder']) { mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("DELETE FROM bidders WHERE biddersId='$deleteBidder'"); header("Location: index.php"); exit(); } if ($_POST['itemDescription'] AND $_POST['itemPrice'] AND $_POST['winningBidder'] AND $_POST['itemQty']) { mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM transactions WHERE biddersId='$winningBidder'"; $result=mysql_query($sql); $count=mysql_num_rows($result); // If result matched, table row must be 1 row if($count==0){ echo "That Bidder Number is NOT logged in, "; echo "would you like to set this bidder as active?"; echo " Enter 1 for NO or 2 for YES"; echo "<form action= \"process.php\" method= \"POST\">"; echo "<input type =\"text\" name= \"logUser\"/>"; echo "<input type= \"submit\" value = \"Submit\"/>"; $logUser= $_POST['logUser']; exit(); } if ($logUser= 1) { header("Location: inprogress.php"); exit(); } else if ($logUser= 2){ // Add $biddersId and redirect to anypage mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder')"); mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')") or die(mysql_error()); $_SESSION['itemDescription']='$itemDescription'; header("Location: index.php"); exit(); } } echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>"; ob_end_flush(); ?> DeleteBidder and newBidder are the only variables working? When I submit my form the variables are sent to the url in my address bar and not to the php post page (resersend.php). Here is the pertinent html page code (index.html)... Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function showMonth(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","reserv.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <p><font face="arial" size="2" color="#336600">Reservation month:</font> <select name="months" onchange="showMonth(this.value)"> <option value="" selected="selected">Choose One</option> <option value="May 2011">May 2011</option> <option value="June 2011">June 2011</option> <option value="July 2011">July 2011</option> <option value="August 2011">August 2011</option> <option value="September 2011">September 2011</option> <option value="October 2011">October 2011</option> <option value="November 2011">November 2011</option> <option value="December 2011">December 2011</option> <option value="January 2012">January 2012</option> <option value="February 2012">February 2012</option> <option value="March 2012">March 2012</option> <option value="April 2012">April 2012</option> </select> </form></p> </body> </html> And here is the php code from the page (reserv.php) that works with the above html page... Code: [Select] <?php $q=$_GET["q"]; $con = mysql_connect('My_host', 'my_user', 'my_password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $sql="SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' AND MONTH = '".$q."' ORDER BY RID, DATE, SITE"; $result = mysql_query($sql); // Determine the number of reservation dates $number = mysql_numrows($result); // Create drop-down menu of reservation dates print "<font size=\"3\" face=\"Arial\"><b>Select Your Reservation:</b><br> <form action=\"resersend.php\" method=\"post\"> <select name=\"RID\"> <option value=\"\">Choose One</option>"; for ($i=0; $i<$number; $i++) { $RID = mysql_result($result,$i,"RID"); $DATE = mysql_result($result,$i,"DATE"); $SITE = mysql_result($result,$i, "SITE"); $PRICE = mysql_result($result,$i, "PRICE"); print "<option value=\"$RID\">$DATE, $SITE, $PRICE</option>"; } print "</select><p align=left><label><font size=\"3\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br>"; print "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br>"; print "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br>"; print "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br>"; print "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br>"; print "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br>"; print "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br>"; print "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\""; print "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\""; print "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br>"; print "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br>"; print "<p align=left><input type=\"submit\" value=\"Book Now!\" name=\"submit\">"; print "<input type=\"reset\" value=\"reset\" name=\"reset\"></form>"; // Close the database connection mysql_close($con); ?> I am sure this is easy, but any help would be greatly appreciated. Thanks. <?php include("add_p2.php"); //basic pdo connection (with added option for error handling) if (isset($_POST['submit'])) { try { $stmt = $dbh->prepare("INSERT INTO passwords (description, username, password ) VALUES (:description, :username, :AES_ENCRYPT)"); $stmt->bindParam(':description', $description); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); try { $statement->execute(array( "description" => "description", "username" => "username", "password" => "password" )); } catch(PDOException $e) { echo "Exception caught: $e"; } //insert one row $name = 'one'; $value = 1; $stmt->execute(); header( 'Location: localhost/password_added.php' ); exit(); ?> <?php $dsn = "mysql:host=127.0.0.1;dbname=pword_db;charset=utf8"; $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $pdo = new PDO($dsn,'root','', $opt); ?> <form action="add_p.php" method="post"> <span class="cursive">Description: </span><br> <textarea name="description" rows="20" cols="50"></textarea> <br> <span class="cursive">Username: </span><br> <input type="text" name="username" /> <br> <span class="cursive">Password: </span><br> <input type="text" name="password" /> <br> <input type="submit"/> </form>Hi, above is the 3 components that should add form data into MySQL database using PDO. all it's doing is entering empty values, I'm really not sure why this is? please could someone help me with pointing me in the right direction, offer hint's making this work Thanks Attached Files PHPmyadmin.JPG 64.83KB 0 downloads I have a basicc form that takes users info and when they submit it it show on a new web page in the proper order. I need to know how do I skip a blank field. This form takes a users First, Middle, and Last name but many times they leave the middle name blank so I would want to skip this field from showing up when the form is posted. Here is what I have for the basic php script ..Would like to know how to skip a field if it is left blank on the form. echo $_POST["First"], print "."; ?><?php echo $_POST["Middle"], print "."; ?><?php echo $_POST["Last"], print "."; ?><?php echo $_POST["Persona1"], print ".";<br /> Ok. I have read everything I could find on how to fix this problem...but nothing seems to work. I have some suspect reasons why I think it doesn't work, but I don't know how to fix it. I read the notice about posting "headers already sent" and nothing in there helped me either. I am at my wits end! I have a form that is contained in a left navigation file that is an "include" file for other pages of the website. Here is the code for the left navigation file: Code: [Select] <?php //process the email if (array_key_exists('send', $_POST)) { $to = 'jliss32@gmail.com'; $subject = 'Form Submission from JudeLaw LLC for Bankruptcy'; //list expected fields $expected = array('name', 'street','city', 'phone', 'email', 'time', 'hearaboutus', 'otherwho', 'who', 'needs', 'question'); //set required fields $required = array('name', 'street', 'city', 'phone', 'email'); //create empty array for missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { //assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); //if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } //otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { //set default values for variables that might not exist $hearaboutus = isset($hearaboutus) ? $hearaboutus : 'Nothing selected'; $needs = isset($needs) ? $needs : array('None selected'); //build the message $message = "$name\n\n"; $message .= "$street\n\n"; $message .= "$city\n\n"; $message .= "$phone\n\n"; $message .= "$email\n\n"; $message .= "Best time to reach you? $time\n\n"; $message .= "How did you hear about us? $hearaboutus\n\n"; $message .= "Other: $otherwho\n\n"; $message .= "Referred by: $who\n\n"; $message .= 'What do you need? '.implode(', ', $needs). "\n\n"; $message .= "$question\n\n"; //send it $mailSent = mail($to, $subject, $message); if ($mailSent) { // redirect the page with a fully qualified URL header('Location: http://www.judelawllc.com/contact-thank-you-bk.php'); exit; } } } ?> <div id="sidebarItem1"> <p><a href="http://www.referrallist.com/listing/judelaw-llc.html" target="_blank"><img src="http://www.judelawllc.com/images/martinoLogo.gif" width="216" height="168" alt="Tom Martino Referral List" /></a><br /> <br /> <a href="http://www.bbb.org/denver/business-reviews/60075-112/jude-law-llc-90107441" target="_blank"><img src="http://www.justgoodbusiness.biz/logoonline/getimage.php?bid=90107441&c=blue&h=1" width="187" height="83" border="0" title="Click to verify BBB accreditation and to see a BBB report." alt="Click to verify BBB accreditation and to see a BBB report." /></a></p> <p><img src="http://www.judelawllc.com/images/ColoradoBarAssoc_Logo.jpg" width="180" height="40" alt="Colorado Bar Association" /></p> <p><img src="http://www.judelawllc.com/images/nacba-logo.jpg" width="180" height="35" alt="National Association of Consumer Bankruptcy Attorneys" /></p> <!-- start RatePoint Widget - Please, do not change --> <iframe src="//sitetools.ratepoint.com/widget/36561?style=2&color=3&wide=1&number_of_reviews=1&average_rating=1&rotate_reviews=1&show_links=1" width="200" height="204" scrolling="no" frameborder="0" border="0"> </iframe> <p> <!-- end RatePoint Widget - Please, do not change --> </p> <A class=the_url href="http://ratepoint.com/tellus/36561" target=_blank>Rate us and write a review!</A> </div> <div id="sidebarItem4"> <h1 class="FormFill">Fill out the form below...<br /> Get a Call TODAY!</h1> <div id="sidebarItem4Content"> <?php if ($_POST && isset($missing) && !empty($missing)) { ?> <p class="warning">Please complete the missing item(s) indicated.</p> <?php } elseif ($_POST && !$mailSent) { ?> <p class="warning">Sorry, there was a problem sending your message. Please try again later. If you need immediate assistance, please call(303)757-5833! Thank you.</p> <?php } ?> <form id="contact" method="post" action=""> <p> <label for="name">Name:<?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your name</span><?php } ?></label><br /> <input name="name" id="name" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['name']).'"'; } ?> /> </p> <p> <label for="street">Street Address:<?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your street address</span><?php } ?></label><br /> <input name="street" id="street" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['street']).'"'; } ?> /> </p> <p> <label for="city">City/State/Zip<?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your city/state/zip</span><?php } ?></label><br /> <input name="city" id="city" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['city']).'"'; } ?> /> </p> <p> <label for="phone">Phone:<?php if (isset($missing) && in_array('phone', $missing)) { ?> <span class="warning">Please enter your phone number</span><?php } ?></label><br /> <input name="phone" id="phone" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['phone']).'"'; } ?>/> </p> <p> <label for="email">E-mail:<?php if (isset($missing) && in_array('email', $missing)) { ?> <span class="warning">Please enter your email</span><?php } ?></label><br /> <input name="email" id="email" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"'; } ?>/> </p> <p> <label for="select">Best Time To Reach You?</label><br /> <select name="time" id="time"> <option value="No reply" <?php if (!$_POST || $_POST['time'] == 'No reply') { ?> selected="selected" <?php } ?> >Select one</option> <option value="Any" <?php if (isset($missing) && $_POST['time'] == 'Any') { ?> selected="selected" <?php } ?> >Any</option> <option value="Morning" <?php if (isset($missing) && $_POST['time'] == 'Morning') { ?> selected="selected" <?php } ?> >Morning</option> <option value="Afternoon" <?php if (isset($missing) && $_POST['time'] == 'Afternoon') { ?> selected="selected" <?php } ?> >Afternoon</option> <option value="Evening" <?php if (isset($missing) && $_POST['time'] == 'Evening') { ?> selected="selected" <?php } ?> >Evening</option> </select> </p> <fieldset id="hearaboutus"> <p><strong class="FormText">How did you hear about us?</strong></p> <p> <input name ="hearaboutus" type="radio" value="Google" id="google" <?php $OK = isset($_POST['hearaboutus']) ? true:false; if($OK && isset($missing) && $_POST['hearaboutus'] == 'Google') { ?> checked="checked" <?php } ?> /> <label for="google">Google</label> <input name ="hearaboutus" type="radio" value="Yahoo" id="yahoo" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Yahoo') { ?> checked="checked" <?php } ?> /> <label for="yahoo">Yahoo</label> <input name ="hearaboutus" type="radio" value="Bing" id="bing" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Bing') { ?> checked="checked" <?php } ?> /> <label for="bing">Bing</label> <br /> <input name ="hearaboutus" type="radio" value="Tom Martino" id="tommartino" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Tom Martino') { ?> checked="checked" <?php } ?> /> <label for="tommartino">Tom Martino</label> <input name ="hearaboutus" type="radio" value="Craigslist" id="craigslist" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Craigslist') { ?> checked="checked" <?php } ?> /> <label for="craigslist">Craigslist</label> <br /> <input name ="hearaboutus" type="radio" value="Backpage" id="backpage" <?php if($OK && isset($missing) && $_POST['hearaboutus'] == 'Backpage') { ?> checked="checked" <?php } ?> /> <label for="backpage">Backpage</label> <input name ="hearaboutus" type="radio" value="Facebook" id="facebook" <?php if($OK && isset($missing) && $_POST['hearaboutus'] == 'Facebook') { ?> checked="checked" <?php } ?> /> <label for="facebook">Facebook</label> <br /> <input name ="hearaboutus" type="radio" value="AngiesList" id="angieslist" <?php if($OK && isset($missing) && $_POST['hearaboutus'] == 'AngiesList') { ?> checked="checked" <?php } ?> /> <label for="angieslist">Angie's List</label> <br /> <input name ="hearaboutus" type="radio" value="Other" id="othersite" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Other') { ?> checked="checked" <?php } ?> /> <label for="othersite">Other</label><br /> <label for="otherwho">Please tell us where?</label><br /> <input name="otherwho" type="text" class="formbox" id="otherwho" value="" size="22" <?php if (isset($missing)) { echo 'value="'.htmlentities($_post['otherwho']).'"'; } ?>="<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['otherwho']).'"'; } ?>" /> <br /> <input name ="hearaboutus" type="radio" value="Referral" id="referral" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Referral') { ?> checked="checked" <?php } ?> /> <label for="referral">Referral</label><br /> <label for="who">Who referred you?</label><br /> <input name="who" type="text" class="formbox" id="who" value="" size="22" <?php if (isset($missing)) { echo 'value="'.htmlentities($_post['who']).'"'; } ?>="<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['who']).'"'; } ?>" /> </p> </fieldset> <fieldset id="needs"> <p><strong class="FormText">What do you need?</strong></p> <p> <input type="checkbox" name="needs[]" value="I Want a Free Consultation" id="consult" <?php $OK = isset($_POST['needs']) ? true: false; if ($OK && isset($missing) && in_array('Schedule a showing', $_POST['needs'])) { ?> checked="checked" <?php } ?> /> <label for="consult">I Want a Free Consultation</label> <br /> <input type="checkbox" name="needs[]" value="Have a question" id="havequestion" <?php if ($OK && isset($missing) && in_array('Have a question', $_POST['needs'])) { ?> checked="checked" <?php } ?> /> <label for="haveaquestion">I Have A Question</label> </p> </fieldset> <p> <label for="question">How may we help you?</label><br /> <textarea name="question" cols="22" class="formbox" id="question" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['question']).'"'; } ?>"></textarea> </p> <p> <input name="send" id="send" type="submit" value="Send message" /> <input name="reset" id="reset" type="reset" value="Reset Form" /> </p> </form> <br /> </div> </div> Everything worked fine until I wanted to redirect the user to another page for email confirmation. I need to have the user go to a new page so I can use the Google Analytics tracking code for PPC campaigns. So, here is a sample of how this file is included in other pages of the site. I suspect this is the problem, the other pages contain HTML before this file is included. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" /> <title>Thank You! | JudeLaw LLC</title> <meta name="description" content="JudeLaw has a qualified and experienced attorney that practices in all (5) Federal Bankruptcy Courts in Colorado. JudeLaw is the lawyer with the experience that is able to file your case not only in the Denver Bankruptcy Court, but also in Fort Collins, LoveLand, Greeley, Colorado Springs, Grand Junction and Pueblo bankruptcy courts." /> <meta name="keywords" content="about JudeLaw, judelaw, jude law, bankruptcy, personal injury, attorney, lawyer, judelaw employees" /> <!-- STYLES --> <link href="http://www.judelawllc.com/styles/base.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="outerWrapper"> <div id="headerWrapper"><img src="../images/header-logo-01.jpg" width="800" height="137" alt="JudeLaw LLC" /></div> <div id="navWrapper"><?php require ('includes/mainNav.php'); ?></div> <div id="bodyWrapper"> <div id="sidebarWrapper"><?php require ('includes/content-nav-sidebar_thank.php'); ?></div> <div id="contentContainer"> <div id="contentContainerTitle"> <h1>Thank You for contacting us!</h1> </div> <div id="contentContainerBody"> <h5>Your message has been sent.</h5> <p>We will review your inquiry and will be able to help you with your situation very shortly. Thank you for considering Jude Law for your legal needs. <br /><br />If you need immediate assistance, please call 303-757-5833 and someone will be able to assist you. Thank you!</p> <!-- Google Code for contact form thank you Conversion Page --> <script type="text/javascript"> <!-- var google_conversion_id = 1035626379; var google_conversion_language = "en"; var google_conversion_format = "2"; var google_conversion_color = "ffffff"; var google_conversion_label = "9RXqCPXzgwEQi8_p7QM"; var google_conversion_value = 0; if (800.00) { google_conversion_value = 800.00; } //--> </script> <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"> </script> <noscript> <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1035626379/?value=800.00&label=9RXqCPXzgwEQi8_p7QM&guid=ON&script=0"/> </div> </noscript> <SCRIPT> microsoft_adcenterconversion_domainid = 799687; microsoft_adcenterconversion_cp = 5050; microsoft_adcenterconversionparams = new Array(); microsoft_adcenterconversionparams[0] = "dedup=1"; </SCRIPT> <SCRIPT SRC="https://0.r.msn.com/scripts/microsoft_adcenterconversion.js"></SCRIPT> <NOSCRIPT><IMG width=1 height=1 SRC="https://799687.r.msn.com/?type=1&cp=1&dedup=1"/></NOSCRIPT><a href="http://advertising.microsoft.com/MSNadCenter/LearningCenter/adtracker.asp" target="_blank">::adCenter::</a> <SCRIPT language="JavaScript" type="text/javascript"> <!-- Yahoo! Inc. window.ysm_customData = new Object(); window.ysm_customData.conversion = "transId=,currency=,amount="; var ysm_accountid = "1TKLPE8MB57H8SOJHVOE3OU6KOO"; document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " + "SRC=//" + "srv3.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid + "></SCR" + "IPT>"); // --> </SCRIPT> </div> </div> <div class="clear"></div> <div id="footerWrapper"><?php require ('includes/footer.php'); ?></div> </body> </html> Please give me some new ideas on what to try in order to make this work. I just need to have the redirect work so I can still use the code for analytics to track conversions. Thank You! Mod edit: [code] . . . [/code] tags added. Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? Hi. I'm brand new to this forum, so sorry if I do something wrong... I'm someone who has thought myself to code in php to add dynamic objects to my basic static websites. I have had no formal education. This is not my first project however. I'm having problems with session variables working fine up to a point when I call a new file and then all my session variables are lost. I have tried everything, but cannot keep them alive when I get into this or any other new file. I display a form, get user data submitted, then display a next form and after the user submits this next form all the session variables are lost. Anyone have any idea what is killing my session variables? Thanks in advance. ...anyone know anything about Internet Explorer not printing values from session variables. It works on Firefox but not on Internet Explorer. The session variable value works find on the web page but click on Print preview and it dissapears and will not print. Say I have a dropdown menu consisting of user specific options. I need to be able to set a session variable depending on the option chosen & then re-access it on the following page. Can someone give me a crash course on how to utilize session variables? they recently reset my website so my php.ini file has been adjusted. One of my sites is no longer passing a session variable to the next page. I am sure its one of the settings being reset. here is the data from my phpinfo file. Anything that looks off to anyone? session Session Support enabled Registered save handlers files user sqlite Registered serializer handlers php php_binary wddx Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_httponly Off Off session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 100 100 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.hash_bits_per_character 4 4 session.hash_function 0 0 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path /home/users/web/b535/ipw.plevtech/public_html/cgi-bin/tmp /home/users/web/b535/ipw.plevtech/public_html/cgi-bin/tmp session.serialize_handler php php session.use_cookies On On session.use_only_cookies Off Off session.use_trans_sid 0 0 Hi Can some steer me in the right direction. I am having issues subtotaling 2 session variables: <td>'.$_SESSION['itemqty'][$key].'*'.$_SESSION['itemprice'][$key].'</td> Can you advise if I am doing this right? Cheers I have some difficulty identifying why the session variables' values have disappeared in my PHP code. When I try to echo their values, nothing shows up and when I try to compare the values, it does not work.
There are no error messages to indicate something has gone wrong?
Can someone assist?
Attached Files
x.txt 6.29KB
1 downloads Hi All! I've written up a script for my website. It\ is basically a virtual job quest. My queries are all correct it just isn't registering the variable for the session. It is $-SESSION[theid']. I want to be bale to use it in my table but I get an error. How do I write this in my SQL query for it to work. The page (when no errors), doesn't show my data. Here is my ocde: Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Messages</font><br><br></center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Basic Quests</font><br><br>"; $startjob = $_POST['submit']; $jobq = "SELECT * FROM jobs WHERE username='$showusername'"; $job = mysql_query($jobq); $jobnr = mysql_num_rows($job); if($jobnr == "0") { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="submit" name="submit" value="Start Job"></form> <?php } if(isset($startjob)) { $initemidq = "SELECT * FROM items ORDER BY RAND() LIMIT 1"; $initemid = mysql_query($initemidq); while($ir = mysql_fetch_array($initemid)) { $ids = $ir['itemid']; } mysql_query("INSERT INTO jobs (username, item, time, completed) VALUES ('$showusername', '$ids', 'None', 'No')"); $wegq = "SELECT * FROM items WHERE itemid='$ids'"; $weg = mysql_query($wegq); while($wg = mysql_fetch_array($weg)) { $im = $wg['image']; $nm = $wg['name']; $id = $wg['itemid']; } $_SESSION['theid'] = $id; echo "<font color=green>Success! You have started this Job!</font><br><br>Please bring me this item: <b>$nm</b><br><br><img src=/images/items/$im><br><br><br>"; echo $_SESSION['theid']; } if($jobnr == "1") { $finish = $_POST['finish']; $okgq = "SELECT * FROM items WHERE itemid='$yes'"; $ok = mysql_query($okgq); while($ya = mysql_fetch_array($ok)) { $okname = $ya['name']; $okid = $ya['itemid']; $okimage = $ya['image']; } echo "Where is my <b>$okname</b>?<br><br><img src=/images/items/$okimage><br><br><br>"; echo $_SESSION['theid']; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="submit" name="finish" value="I have the Item"></form> <?php } } if(isset($finish)) { $cinq = "SELECT * FROM uitems WHERE theitemid='$_SESSION[theid]'"; $cin = mysql_query($cinq); $connr = mysql_num_rows($cin); if($connr != "0") { echo "<font color=green>Success! You have the item.</font>"; } else { echo "<font color=red>Error! You do not have my item!</font>"; } } ?> . I basically just want to know how I can set this session as a variable. Also..I have a user login on every page and I want to be able to destroy JUST THE "theid" session and NOT the username session. How would I do that too? thanks for the help in advance! Hi Maybe a strange request and perhaps someone here knows a better way of doing what I want. I have a sign up form on my website that automatically pulls the session var 'name' and places this in the text field for "Reference". That way I know which agent signed up a customer. What I need to do now though is allow this variable to be injected through the url for click through banners. This what I've done (within the header HTML Tags): Code: [Select] if ($_GET['Reference'] == '') { $_SESSION['Name'] = $my->name; } else { $_SESSION['Name'] = $_GET['Reference']; } However, even though this is loaded on EVERY page view the variable is empty if the user clicks another page. |