HhAaZzEeYy Posted August 14, 2007 Share Posted August 14, 2007 The following is a code i wrote for a zipcode/pricing identification page, everything works fine except for the option of setting the cookie.... For some reason at the end function success($cookin) the variable always comes up with yes no matter what and never sets the cookie.... which if its glitching to yes all the time, it should be setting the cookie all the time.... weird... I've tried many a things and i still can't find it.... can anyone help? Too see the code with lines and a little better color goto: www.berlon.com/code.gif <?php if ($_SERVER['REQUEST_METHOD'] != 'POST' and !$_COOKIE["Pricing"]) { topdraw(); ?> <form id="ziplogin" name="ziplogin" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label><span class="series">Enter Zipcode:</span> <input name="zipcode" type="text" class="boldbody" id="zipcode" onKeyPress="return numbersonly(event)" value="" size="8" maxlength="5"/> <br /> <br /> <span class="boldbody14">Yes : <input type="radio" name="cookin" id="cookin" value="yes"> No: <input type="radio" name="cookin" id="cookin" value="no" checked> Remember This Zip Code</span><br /> <br /> <input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> </form> <?php } else { if (!$_COOKIE["Pricing"]) { $zipcode = $_POST["zipcode"]; $cookin = $_POST["cookin"]; } else $zipcode=$_COOKIE["Pricing"]; $con = mysql_connect("localhost","berlonco_berlon","ziplogin"); if (!$con) connecterror(); else { mysql_select_db("berlonco_zipcode", $con); $resulta = mysql_query("SELECT state FROM zipcodes WHERE zip = '$zipcode'"); $statea = mysql_fetch_array($resulta); $state = $statea['state']; $resultb = mysql_query("SELECT discount FROM stateprice WHERE state = '$state'"); $disca = mysql_fetch_array($resultb); $discount = $disca['discount']; mysql_close($con); } if (!$state) ziperror($zipcode); else { if ($cookin = "yes") cookieset(); $_SESSION['discount']=$discount; $_SESSION['zipcode']=$zipcode; success($cookin); } } die(); function cookieset() { $inThreeMonths = 60 * 60 * 24 * 90 + time(); setcookie('Pricing', $zipcode, $inThreeMonths); } function topdraw() { ?> <title>Pricing Login</title> <style type="text/css" media="screen"> @import "css/berlon.css"; body {background-color:#ffffff;} </style> <script type="text/javascript"> function numbersonly(e){ var unicode=e.charCode? e.charCode : e.keyCode if (unicode!={ //if the key isn\'t the backspace key (which we should allow) if (unicode<48||unicode>57) //if not a number return false //disable key press } } </script> </head> <body> <table width="400" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td><div align="center"><span class="maintitle">Pricing Login</span><br /> <span class="uses">Enter your zipcode to find pricing in your area.</span><br /> <br /> </div></td> </tr> <tr> <td align="center">'; <?php } /** If Failed Connection Do The Folowing **/ function connecterror() { topdraw(); echo '<span class="parhead">!!! Error Connecting to Database !!!</span><br /><br /><span class="boldbody">Please try again or contact Berlon if problem persists!<br /><br /><input name="Try Again" type="button" id="Try Again" value="Try Again" onClick="location.reload(true)"/><input name="Go Back" type="button" id="Go Back" value="Go Back" onClick="history.go(-1)"/></span>'; die(); } /** If ZipCode Doesn't Exist **/ function ziperror($zipcode) { topdraw(); echo '<span class="parhead">!!! Error: Zip Code not Found !!!</span><br /><br /><span class="boldbody">Please go back and make sure you entered the proper Zip Code<input name="Go Back" type="button" id="Go Back" value="Go Back" onClick="history.go(-1)"/><br /><br />If you feel we are missing your Zip Code please contact us or fill out our <a href="zipmissing.php?zip='.$zipcode.'">Missing Zipcode</a> Form.</span>'; die(); } /** Final Sucess **/ function success($cookin) { topdraw(); echo '<span class="parhead">Done with all procedures</span><br /><span class="boldbody">Your zipcode is: '.$_SESSION['zipcode'].'<br />And your discount level is: '.$_SESSION['discount'].'</span><br />Cookie value:'."$cookin"; } ?> <br /></td></tr></table> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/64937-solved-help-cookie-code-glitch/ Share on other sites More sharing options...
HhAaZzEeYy Posted August 15, 2007 Author Share Posted August 15, 2007 NM i found it, i was missing a stupid " = " grrr..... Quote Link to comment https://forums.phpfreaks.com/topic/64937-solved-help-cookie-code-glitch/#findComment-324810 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.