PHP - How To Create A Form With A Submit Button That Saves The Checked Box To A $_session And Create A Link To A Different Php That Takes On The $_session.
Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Similar TutorialsHi all, here's my code: Code: [Select] <?php foreach ($_SESSION['topping'] as $value) { echo "<tr><td width='30%'>Topping</td><td width='50%'>$value</td><td width='20%'><select name='notopping'>"; foreach ($_SESSION['cupcake'] as $number) { '<option name="notoppings[]" value="'.$number.'">".$number."</option>'; } echo "</select></td></tr>"; } ?> $_SESSION['cupcake'] is a value from either 6, 12, 24 or 36. What I want to do is put them into a drop down box (second foreach) as the value and the displayed value - counting up from 1 (so 1,2,3,4,5,6 or up to 12,24 etc). Also by creating this as an array, does this mean than for each topping (say Vanilla and Chocolate) the value dynamically created can be used on the next page by using $_POST['notoppings'] to display each type (two different numbers - one for Vanilla and one for Chocolate). Does that make sense? Thanks! Jason
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Driving myself nuts...can't figure out what is wrong with this code. This is part of a pagination system that uses an array instead of hitting the db each time. I am using CodeLobster PHP version (3.7), Windows 7, and using a virtual server on my computer for development (XAMPP) the error I get is this: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\website\searchinv.php on line 45 Warning: array_multisort() function.array-multisort: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\website\searchinv.php on line 49 Warning: array_slice() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\website\searchinv.php on line 108 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\website\searchinv.php on line 146 I am pasting the code below and point out each of the lines in the warnings above, and will try to clean up some so that it's not too extensive... Here is the problem: If I click on any of the "page" $_SESSION['rows'] has all the correct information contained in it. However, if I trigger the "re-sort" select option...$_SESSION['rows'] is empty...all my other $_SESSION variables are still there. At first I thought it was an issue with too many "if/ifelse/else" statements or a wrong syntax...so I changed it to a "switch" and traced it closely. I don't see anything wrong. Next I thought it was caused by the JavaScript "onchange" event...so I took that out...and replaced it with just a submit button...same result. I've done a search on the page for EVERY $_SESSION['rows'] and found only 4 and none of them should blank it out...I've been going crazy on this code for 2 days I'm pulling my hair out now...can ANYONE help? Code: [Select] if(!empty($_POST)) { if(empty($_POST['page'])) { switch($_POST) { case (!empty($_POST['ref'])): $deleted=sql_ending($_POST['del']); $rows=select_from_database('inventory', '*', 'ref_number=\''.$_POST['ref'].'\' and '.$deleted); break; case (!empty($_POST['type'])): $sort=$_POST['sort']; $deleted=sql_ending($_POST['del']); if($_POST['type']!='*') { $type=$_POST['type']; $len=strlen(trim($type)); if($len!=1) $type=$type.'-'; $end=$deleted.' and ref_number like \''.$type.'%\''; } else $end=$deleted; $rows=select_from_database('inventory', '*', $end, $sort); break; default: $data=$_SESSION['rows']; $sorts=explode(' ', $_POST['sort']); $keys=$sorts[0]; $order=$sorts[1]; Line 45 --> foreach ($data as $key => $row) { $column[$key]=$row[$keys]; } Line 49 --> $rows=array_multisort($column, $order, $data); break; } $_SESSION['rows']=$rows; } $x=count($_SESSION['rows']); if(isset($_SESSION['admin_user'])) $width=1280; else $width=900; $srch_rslt= ' <div id="displaybox"> <div id="translucent"></div> <div id="result" style="width:'.$width.'px;"> <!--[if lt IE 7]> <h3 class="center">This site looks much better with IE 7 and above. Please consider upgrading <a href="browsers.php">HERE</a>.</h3> <![endif]--> '; if($x==0) $srch_rslt.=' <h3>Search Result</h3> <a style="display: block; margin-right:10px;" href="searchinv.php" title="Close this box.">Close <img src="images/close.png" alt="Close this box." /></a> <p>We are sorry, but we currently do not have the equipment available for the given search. Please go back and <a href="searchinv.php" title="Search Again">search again</a>, or <a href="mailto:mywebsite@mywebsite.com" title="Send us an email so we can locate the equipment you need." onclick="popup(\'email.php?title=pray\', \'Request for Equipment\', 500, 500); return false">contact us</a> so we may begin to utilze are vast resources to locate your needs. </div> </div> '; else { if(empty($_POST['page'])) $pg=1; else $pg=$_POST['page']; $page=($pg-1)*20; $_SESSION['pages']=ceil($x/20); if(!$_SESSION['pages']>1) $buttons='<button type="button" class="active" title="Page 1">1</button> '; elseif($pg>1) { $prev_pg=$pg-1; $buttons='<button type="submit" class="button" title="First" value="1" name="page"><< First</button> <button type="submit" class="button" title="Previous" value="'.$prev_pg.'" name="page">< Prev</button> '; } for($i=1; $i<=$_SESSION['pages']; $i++) { if($i==$pg) $buttons.=' <button type="button" class="active" title="Page '.$pg.'">'.$pg.'</button> '; else $buttons.=' <button type="submit" class="button" title="Page '.$i.'" value="'.$i.'" name="page">'.$i.'</button> '; } if($pg<$_SESSION['pages']) { $next_pg=$pg+1; $buttons.=' <button type="submit" class="button" title="Next" value="'.$next_pg.'" name="page">Next ></button> <button type="submit" class="button" title="Last" value="'.$_SESSION['pages'].'" name="page">Last >></button> '; } Line 108 --> $results=array_slice($_SESSION['rows'], $page, 20, true); $srch_rslt.=' <h3>Search Complete!</h3> <a class="close" href="searchinv.php" title="Close this box.">Close <img style="border:none;" src="images/close.png" alt="Close this box." /></a> <p>You may now browse, re-sort and download your results in either PDF or an Excel format.</p> '; if (isset($_SESSION['admin_user'])) $table = 1260; else $table = 880; $tableinner = $table-20; $srch_rslt.=' <form name="search_page" method="post" action="searchinv.php?search='.$_POST['search'].'"> <div style="border:2px solid #00000; width:'.$table.'px;"> /* there's a table here */ '; $y=0; Line 146 --> foreach($results as $result) { $y++; $cl_type=explode('-', $result['ref_number']); $type=select_from_database('car_types', '*', 'abbvr=\''.$cl_type[0].'\''); $raw_notes=$result['notes']; if ($raw_notes == NULL) $notes="Call for additional information."; elseif (strlen($raw_notes) >65) { $txtlth=strpos($raw_notes, " ", 65); $notes=substr($raw_notes, 0, $txtlth).'<span id="para'.$pg.$y.'" class="jshide"> '.substr($raw_notes, $txtlth).'</span><a class="jsunhide" href="javascript:function(){};" onclick="toggleMe(\'para'.$pg.$y.'\', \'href'.$pg.$y.'\')" id="href'.$pg.$y.'" style="text-decoration: none">...[click for more]</a>'; } else $notes=$raw_notes; $srch_rslt.=' /*just some html output stuff */ $srch_rslt.=' </table> </div> <div> <input type="hidden" name="search" value="'.$_POST['search'].'" /> <p class="center"> '.$buttons.' </p> </div> </td> </tr> </table> </div> </form> <div class="search_menu_wrapper"> <ul class="sermenu"> <li>Need to search again? Back to the <a href="searchinv.php" title="Do another search.">search page</a>.</li> <li>Download this search to a <a href="http://www.mywebsitedowloadpdf.php?search='.$_POST['search'].'" title="Download to .pdf.">.pdf <img src="images/adobe.png" style="width:15px; height:15px; border:none;" alt="Download in Adobe PDF format." /></a></li> <li>Download this search to a <a href="http://www.mywebsitedowloadexcel.php?search='.$_POST['search'].'" title="Download to MS Excel.">MS Excel <img src="images/excel.png" style="width:15px; height:15px; border:none;" alt="Download in MS Excel format." /></a></li> </ul> </div> Like I said if I click a "page" button (stored in the $buttons var and printed above)...the code works beautifully...it's when the next lines (below) are triggered that cause $_SESSION['rows'] to be empty...I just don't get it Code: [Select] <div style="text-align:center;"> <form name="re_sort" method="post" action="searchinv.php?search='.$_POST['search'].'"> <label class="form-label-left" id="l_sort" for="sort">Re-Sort By:</label> <div class="form-input"> <select class="form-dropdown" style="width:190px" id="sort" name="sort" onchange="this.form.submit();"> <option value="ref_number SORT_ASC" selected="selected"> Reference Number - Ascending </option> <option value="ref_number SORT_DESC"> Reference Number - Descending </option> <option value="date_added SORT_ASC"> Date Added - Ascending </option> <option value="date_added SORT_DESC"> Date Added - Descending </option> <option value="last_update SORT_ASC"> Date Updated - Ascending </option> <option value="last_update SORT_DESC"> Date Updated - Descending </option> '; if($_SESSION['admin'] == 10) $srch_rslt.=' <option value="source SORT_ASC"> Source - Ascending </option> <option value="source SORT_DESC"> Source - Descending </option> '; $srch_rslt.=' </select><button type="submit" value="submit">Submit</button> </div> </form> </div> </div> </div> <script type="text/javascript" language="javascript"> //<![CDATA[ document.body.style.overflow="hidden"; //]]> </script> '; } } echo $srch_rslt; The below should choose the radio button that is set by the $_SESSION variable or default to 3. However, it's defaulting to 1. Code: [Select] $content.=' <p class="form_item"><label>Product Rating:</label><br /> <div class="rating_radio"><input type="radio" name="review_product_rating" value="1"'; if(isset($review_product_rating) && $review_product_rating=="1"){$content.='checked';} $content.=' /> <br />1</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="2"'; if(isset($review_product_rating) && $review_product_rating=="2"){$content.='checked';} $content.=' /> <br />2</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="3"'; if(isset($review_product_rating) && $review_product_rating=="3" || !isset($review_product_rating)){$content.='checked';} $content.=' /> <br />3</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="4"'; if(isset($review_product_rating) && $review_product_rating=="4"){$content.='checked';} $content.=' /> <br />4</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="5"'; if(isset($review_product_rating) && $review_product_rating=="5"){$content.='checked';} $content.=' /> <br />5</div> <div class="worst">(Worst)</div><div class="best">(Best)</div> </p> I'm figuring it's because it's multiple if statement (with no elseif) so it's evaluating the first if and being set to true. I tried changing everything else after the first one to elseif, and it's throwing an unexpected T_ELSEIF error. Hi, how can i create a form within a form with the click of a button? so that when i click add new item, it brings form fields under the current one. hope my explanation helps thanks Code: [Select] <form id="form1" name="form1" method="post" action=""> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="22%">Invoice Number </td> <td width="78%"> </td> </tr> <tr> <td>Date Issued </td> <td> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"><table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="10%">Quantity</td> <td width="70%">Description</td> <td width="9%">Taxable</td> <td width="11%">Amnount</td> </tr> <tr> <td valign="top"><input name="textfield" type="text" size="7" /></td> <td valign="top"><textarea name="textfield2" cols="80"></textarea></td> <td valign="top"><input type="checkbox" name="checkbox" value="checkbox" /></td> <td valign="top"><input name="textfield3" type="text" size="12" /></td> </tr> <tr> <td colspan="4"><input type="submit" name="Submit" value="Add New Item" /></td> </tr> </table></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> Hope someone can help put with this - I have inherited a site and am trying to modify some PHP that I am unfamiliar with. I have gotten so far with it, but still have a problem with it.
Its a page on an online store offering optional extras depending on the product. The products are furniture, so and there was an option to buy cushions for some. The change I am trying to make is to have an option for two different sizes of cushion depending on the product.
So there was a field 'cushions' in the product table, and a page 'accessories.php' that offered the option to add cushions.
I have added a new field 'cushions2' and a new page 'accessories2.php' to cover the new size of cushions.
The site is here, with this example product:
http://www.lloydloom...oduct.php?id=32
If you click 'Add to cart' the next page offers you the option to add custom paintwork.
If you enter something there, and click on 'Add colour to order' it works - i.e. the next page is the one offering the cushions.
But if you just click on 'No thank you, proceed with order' it just reloads the page - basically the URL isn't being puled through as it should be.
On that page the PHP at the top of the page looks like this:
<?php session_start(); i have an html form which is a "post" on it i have an array of checkboxes and a sumbit button, once button is clicked i go to another page where i handle those boxes checked the problem now is if NO checkboxes are checked and i hit the submit...i get errors on the other page my code: foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName(); ?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" /></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" /></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type='submit' name='submit' value='Submit'> <?php if ( (isset($graphic)) || (isset($text) )) { echo "checkboxes checked"; //show submit button } else { //hide submit botton and echo "no boxes check"; } ?> the above is NOT working please help???? Hi I've got this database I created with fields ProductId ProductName Image I've managed to get it to list the ID,productname, and Image urls in a list. My next step is to have the image field actually display an image and make it clickable: heres what I've done so far: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("productfeed", $con); $result = mysql_query("SELECT * FROM productfeeds"); echo "<table border='0'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Image</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; echo "<td>" . $row['ImageURL'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Heres what I want to do: Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; // my changes beneath echo "<td>" . <a href="<?php echo $row['ImageURL'];?>"> <img src="<?php echo $row['LinkURL']; ?>"> </a>. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Can you guys point me in the right direction? Many thanks edited Hi i have made a login in system for a website iam trying to make. after you log in im trying to display the members username via the $_session created in the check_login.php. but when i Echo or print_r the $_session all is get is "welcome array" its like its not passing any information via the $_session from page to page. here is my code thanks in advance. Check_login.php session_start(); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=md5($_POST["mypassword"]); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $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==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"]==$myusername; $_SESSION["mypassword"]; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> login_success.php <? session_start(); if($_SESSION['myusername']="$myusername"){ header("location:main_login.php"); } Echo "welcome" . $_SESSION['$myusername']; ?> thanks The $_Session has a url variable. Using a Dom how do I properly do: Code: [Select] html->load($_SESSION['variable']) I was thinking about breaking down the session to retrieve the value inside but I don't know how. For the last few hours I have been pulling my hair out on a session not storing when I moved from local host to my vps. I have been setting sessions like: $_SESSION['mydata'] = $variable; This works no problem on my wamp installation. However to get it to work on my vps, I have to store them like this $_SESSION[mydata] = $variable; Can someone please explain to me why this is the case? PHP 5.3.3 I am trying to redirect a user (currently logged in) to a page where they are able to edit a posted comment. To keep things secure I am using a forms hidden input value to pass the {postID} to a redirect page Code: [Select] <form name="post_edit" method="post" action="post-edit-redirect.php" > <input type="hidden" name="local" id="local" value="<?php echo $row_rsPosts['postID']; ?>" /> <input type="image" src="../imgs/managepost.png" name="submit" /> </form> On the redirect page (simplified below) I am setting the {postID} in a SESSION before redirecting to the user to the page to edit their post with the new $_SESSION val for {postID} set. Code: [Select] session_start(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); This is working fine in every browser except IE (some one please just put an end to it), where when the edit-post.php page is reached the $_SESSION['postID'] is empty. If I regenerate the session ID from the redirect page as below IE then sets the SESSION ok. Code: [Select] session_start(); session_regenerate_id(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); However there should be no need to do this and would rather not if there is no need. Any help on why IE is not setting the SESSION is appreciated, and I hope I am not covering old ground here however I am unable to find a solution anywhere. - Cheers Hey, i was reading some code and i find this: if(stristr($_SESSION["s"]["user"]["asdasd"]),$someString) How the double/triple [] in $_SESSION works ? PS: I tryied to google it but it was kinda hard to search :X Thanks. Just wanted to know if $_Session was a global thing or does php require cookies setup?
I assumed that I could do something like this:
PAGE: A.php session_start(); $_Session['Cat'] = 'Meow'; // ----------------------- PAGE: B.php if (isset($_Session['Cat']) && !empty($_Session['Cat'])){ echo $_Session['Cat']; } OUTPUT: Meow // ----------------------- PAGE: C.php if (isset($_Session['Cat']) && !empty($_Session['Cat'])){ echo $_Session['Cat']; } OUTPUT: MeowI can't seem to get this to work. Page: Handler.inc // ========================================================= Session Log in / out public function logon($username, $password){ if ($username == "admin" && $password == "coffee"){ session_start(); $_SESSION['USER_STATUS'] = '1'; echo 'IN SESSION LOGIN HANDLER'; echo $_SESSION['UserLogged']; } } public function logout(){ $_SESSION['USER_STATUS'] = '0'; echo 'IN SESSION LOGOUT HANDLER'; session_destroy(); //session_unset(); }Page: index.php if (!isset($_SESSION['USER_STATUS']) && empty($_SESSION['USER_STATUS']) || $_SESSION['USER_STATUS'] == 0){ if (isset($_POST['username']) && !empty($_POST['username']) && isset($_POST['password']) && !empty($_POST['password'])){ $username = $_POST['username']; $password = $_POST['password']; echo $handler->logon($username, $password); } <LOGIN FORM CODE> }else{ if (isset($_SESSION['USER_STATUS']) && !empty($_SESSION['USER_STATUS']) || $_SESSION['USER_STATUS'] == 1){ echo 'Session name: '. $_SESSION['USER_STATUS']; } if (isset($_POST['btn_logout']) && !empty($_POST['btn_logout'])){ $handler->logout(); echo '<br />Logged out<br />'; } <LOGOUT FORM BUTTON CODE> }Could someone point me in the right direction please. It does not seem to hold its session. Hello, I am currently making a small website that requires two languages. This is the class I made: Code: [Select] <?php class languages { public function __construct() { if(!isset($_SESSION['language'])) { $_SESSION['language'] = 'nl'; } $lang = isset($_GET['lang']) ? $_GET['lang'] : ""; $languages = array('en', 'nl'); if(in_array($lang, $languages)) { $_SESSION['language'] = $lang; } } } $languages = new languages; $language = $_SESSION['language']; ?> Now as soon I use index.php?lang=en, the website will display it self in English but, as soon I remove the &lang=en from the URI, the language gets not stored in the session and it displays nl agian. Can somebody help me? Thank you! Is there an equivalent to * (any) in a $_SESSION? Something like this: foreach ($_SESSION['cart']['content'][*]['Large'] as $content) { I'm trying to make a link to an SQL database survive though page reloads, and it's not working. Connecting, I use this: function link_to_converted_database() { $link = mysqli_init(); if (!$link) { die('mysqli_init failed'); } if (!mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 1')) { die('Setting MYSQLI_INIT_COMMAND failed'); } if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 50)) { die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed'); } if (!mysqli_real_connect($link, 'redacted', 'redacted', 'redacted')) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } comment( ' Success... ' . mysqli_get_host_info($link) ); if (mysqli_query($link,'USE conversion_database')) { comment("now using conversion_database."); } else { die('Conversion database unusable (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } $_SESSION['mysql_link']=$link; echo "<!--\n"; var_dump($_SESSION['mysql_link']); echo "\n-->\n"; return(true); } Subsequent SQL commands work fine using $_SESSION['mysql_link'], and the var_dump returns: object(mysqli)#2 (17) { ["affected_rows"]=> int(0) ["client_info"]=> string(48) "mysqlnd 5.0.7-dev - 091210 - $Revision: 294543 $" ["client_version"]=> int(50007) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(0) ["host_info"]=> string(24) "192.168.1.101 via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(16) "5.1.48-community" ["server_version"]=> int(50148) ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(194) ["warning_count"]=> int(0) } After a page changes, all my $_SESSION vars work fine except for $_SESSION['mysql_link']. It's still there, but SQL queries bomb, and var_dump returns: Warning: var_dump(): Property access is not allowed yet in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Property access is not allowed yet in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 Warning: var_dump(): Couldn't fetch mysqli in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\voicereader\serverstate.php on line 595 object(mysqli)#1 (17) { ["affected_rows"]=> NULL ["client_info"]=> NULL ["client_version"]=> int(50007) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> NULL ["error"]=> NULL ["field_count"]=> NULL ["host_info"]=> NULL ["info"]=> NULL ["insert_id"]=> NULL ["server_info"]=> NULL ["server_version"]=> NULL ["sqlstate"]=> NULL ["protocol_version"]=> NULL ["thread_id"]=> NULL ["warning_count"]=> NULL } There's got to be a way to save my SQL linkages so that I don't have to reconnect to the SQL database every time I want to see if new data has arrived, but this doesn't seem to be it. My PHP version is PHP 5.3.2.0. Thanks for any help. I have parts of my webpage protected with the following Code: [Select] session_start(); if(!isset($_SESSION['myusername'])){ header("Location:login.php"); } else { $username = $_SESSION['myusername']; } How secure is this? The goal is so people who don't have access to the page (don't have a login account) cannot get access Thanks for any tips |