Jump to content

Exoon

Members
  • Posts

    99
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Exoon's Achievements

Member

Member (2/5)

0

Reputation

  1. I add your if statement to for loop and if i select nothing it still doesn't clear the session foreach($_POST as $key => $value) { // form submitted if(isset($_POST[$key]) && count($_POST[$key])) { // clear session data unset($_SESSION[$key]); // store session data $_SESSION[$key] = $value; } } Edit: I found this while looking on google and it seems to have worked i think, Incase anyone else having the same issue: <form> <input type='hidden' value='0' name='selfdestruct'> <input type='checkbox' value='1' name='selfdestruct'> </form>
  2. i need to let them be able to uncheck them really, I can't figure out how to check if its empty then unset it in my foreach loop, the $key has "brreakfast_toastextras" and $value has "Jam" inside it. I tried this: foreach($_POST as $key => $value) { if( !isset($_POST[$key]) ) { unset($_SESSION[$key]); } else { $_SESSION[$key] = $value; } } It doesn't work though, any ideas?
  3. Hi, Ive got this form: Im using this to store my selections of a form in sessions so they can be recalled if the user goes back to another page of the form. The problem i have is it always has to have 1 selection, If i tick Jam, then untick Jam and tick butter that works fine, But if i uncheck everything then it doesn't clear the array. It always has to have at least 1 entry in the array for some reason? foreach($_POST as $key => $value) { $_SESSION[$key] = $value; } This is the checkbox code im using: <inputtype="checkbox name="<?php echo $course_menuname."extras[]"; ?>" <?php if(in_array("$extraitems", $_SESSION[$course_menuname.'extras'])) { echo "checked"; } ?> value="<?php echo $extraitems; ?>" id="checkbox"> These are the variables: $extraitems contains the "Toast Extras" words, such as Jam, Butter and Flora $course_menuname contains the course such as "breakfast_cereal", "breakfast_toast" then if it has the word extra it does checkbox underneath.
  4. Yes i am just using post fields and they are all being used, unless they are left blank if that matters? This is what i need: $breakfast_cereal = getAnswers('breakfast_cereal'); $breakfast_toast = getAnswers('breakfast_toast'); $breakfast_toastextra = getAnswers('breakfast_toastextra'); $breakfast_colddrinks = getAnswers('breakfast_colddrinks'); $breakfast_hotdrinks = getAnswers('breakfast_hotdrinks'); So i can then just enter them values into a database, there must be an easy solution I just tried both of the solutions you posted but it didn't see to display anything back This is what i tried: $output = array(); while($row = mysql_fetch_array($result)) { $output[$row['course_menuname']] = getAnswers($row['course_menuname']); } echo $output['breakfast_cereal']; and $output = array(); foreach($_POST as $menu => $values) { if(is_array($values)) { $output[$menu] = getAnswers($values); } } echo $output['breakfast_cereal']; I get this error with the 2nd bit of code. Heres some screenshots hopefully clears it up abit what im doing. Admin Panel to add all the choices Front end for user to select their dinner choice This is how they are stored into the DB
  5. How can i automate this so it calls the function for every entry in the database. I want it to check all of the entries in my course_menuname column This is how i want it to end up like: $breakfast_cereal = getAnswers('breakfast_cereal'); $breakfast_toast = getAnswers('breakfast_toast'); $breakfast_toastextra = getAnswers('breakfast_toastextra'); $breakfast_colddrinks = getAnswers('breakfast_colddrinks'); $breakfast_hotdrinks = getAnswers('breakfast_hotdrinks'); This is my table This is what ive got so far $query = "SELECT course_menuname FROM course"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $row[course_menuname] = getAnswers($row[course_menuname]); }
  6. Ah, its working now, thank you very much
  7. I assure you this isn't homework, Im 26 years old but i appreciate your help so far. Am i along the right lines so far? function getAnswers($input) { $input = implode(";", $_POST[$input]); } echo getAnswers('breakfast_cereal'); Im guessing its not working because each of the values in the array dont have the ; at the end any more? Is the way you're suggesting going to end up with the result i want?
  8. i just tried removing that bit of code and i still don't get anything returned.
  9. Hi, I'm still new to php and trying to get this function to work, im not sure what im doing wrong. i want the end result to be like <?php function getAnswers($input) { // Don't bother doing anything if it's an empty array if (!empty($input)) { return; } foreach($_POST[''.$input.''] as $results) { $results = trim($results); $input .= "$results;"; } } echo getAnswers('breakfast_cereal'); ?>
  10. Ive put the download stuff to the top and it works perfectly, can't thank you enough jesirose and xyph. I see what you mean about how neat it can look, Will definitely spend some time sorting out my page now. Thanks so much!
  11. Logic and business separate? You lost me lol. What is wrong with the easy fix you posted. Whats the difference between that and the right fix?
  12. Oh right, didn't know this How do i get around this then, do i have to have an if right at the top of the page then if its that page then include that file ?
  13. Hello, I get an error with your script: Output buffering is active. This needs to be fixed index.php <?php include("config.php"); $pageWeb = $_REQUEST['page']; session_start(); $loggedin = $_SESSION['loggedin']; // Are they loggedin? ?> <!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>Site Tagline Here!</title> <link href="/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"><!-- Open Container --> <div id="header-banner"><!--Open Header Banner --> <div id="login-wrapper1"> <?php if($loggedin == "1") { echo "<div style=\"text-align:center; margin-top:10px;\">Welcome back $_SESSION[username], <a href=\"/logout/\">Logout</a></div>"; }else { ?> <form action="/login/" method="post"> <div class="username"> <div class="label">Username:</div><input name="username" type="text" /> </div> <div class="password"> <div class="label">Password:</div><input type="password" name="password" type="text" /> </div> <div class="submit"> <input name="submit" type="submit" value="Login" /> </div> </form> <form action="/join/" method="post"> <div class="submit"> <input name="submit" type="submit" value="Join" /> </div> </form> <? } ?> </div> </div> <!-- Close Header Banner --> <div id="header-nav"><!--Open Header Nav --> <div class="button-wrapper"><!--Open Button Wrapper --> <div class="button-home" onclick="location.href='/';" style="cursor: pointer;"></div> <?php if ($loggedin == "1") { ?> <div class="button-videos" onclick="location.href='/videos/';" style="cursor: pointer;"></div> <div class="button-search" onclick="location.href='/search/';" style="cursor: pointer;"></div> <? } else { ?> <div class="button-register" onclick="location.href='/register/';" style="cursor: pointer;"></div> <div class="button-join" onclick="location.href='/join/';" style="cursor: pointer;"></div> <? } ?> <div class="button-hosting" onclick="location.href='/hosting/';" style="cursor: pointer;"></div> <?php if($loggedin == "1") { ?> <div class="button-settings" onclick="location.href='/settings/';" style="cursor: pointer;"></div> <?php } else { ?> <div class="button-members" onclick="location.href='/login/';" style="cursor: pointer;"></div> <?php } ?> </div><!--Close Button Wrapper --> </div><!--Close Header Nav--> <div id="content-wrapper"> <!-- Open Content Wrapper --> <? if(isSet($pageWeb)){ if (!(strpos($pageWeb, "http") === false)){ echo "not allowed"; }else{ include($pageWeb.".php"); } } elseif(isSet($p_page)){ if (!(strpos($p_page, "http")===false)){ echo "not allowed"; }else{ include($p_page.".php"); } } else { include("main.php"); } ?> <div id="footer"><img border="0" src="/images/footer-secure.png" /></div> </div> <!-- Close Content Wrapper --> </div><!-- Close Container --> </body> </html>
  14. Hi, Yes i have error reporting on, I don't get any errors. The PHP file starts download the file fine when accessed both ways, The only difference is when accessed directly using hd-file.php in the browser, This video plays. When accessed using index.php?page=hd-file, It doesn't play. $file = $_GET['file']; was me getting ahead of myself, Not doing anything untill i can get a basic download working. With pageWeb i have $pageWeb = $_REQUEST['page']; at the top of my index to get the page info? My host gave me the script as they said my one before wasent very secure and would allow people to put data from elsewhere onto my site. Not 100% what $p_page is for. Cheers
  15. Hi, Thanks for the reply. I tried doing what you said but it didn't fix the video being corrupt when downloading using the index.php?page=hd-file link What exactly doing what you said change? My script worked the same when it was in quotes from what i can see. Cheers
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.