PHP - Guess I've Been Getting Away With This - But Would Like To Fix It Please
Just set up a new wamp environment and in this new [stricter] environment I'm getting masses of warnings I never saw before (mea culpa):-
e.g. Use of undefined constant name - assumed 'name' in C:\wamp\www... This is the sort of thing I have coded.. $_SESSION['address'][name] = $name; then later.... $name = $_SESSION['address'][name]; Should this be changed to... $_SESSION['address']['name'] = $name; and... $name = $_SESSION['address']['name']; Jamie Similar TutorialsHiya peeps, I have a mysql database with a record of all the images a customer uploads on my site, these images are displayed on there account. I can get this to work but the problem I'm facing is I need a minimum of 5 images displayed so if they only upload 2 images for instance I need to detect that and add my "No Image Uploaded" image. But if they have uploaded 5 or more I need to just let them be displayed without adding the "No Image Uploaded" picture. Does anyone have any ideas as I'm very stuck! Many thanks James. I figure i should start learning functions. I cant find any tutors for a more complex function im trying to do. there is a few things that confuses me on how this works. all these loops I created generate a number that looks like this "4-16-6-29-17-9". which is attached to the variable $address. what i want to beable to do is grab the "$address" when I call the function. so every time i call the function it generates a new number. hope someone will help me with this i need to understand this once and for all. function generate() { $chevron1 = rand(1,39); $chevron2 = rand(1,39); $c2 = 0; while ($c2 < 1) { if ($chevron2 == $chevron1) { $chevron2 = rand(1,39); $c2 = 0; }else{ ++$c2; }} $chevron3 = rand(1,39); $c3 = 0; while ($c3 < 1) { if ($chevron3 == $chevron1 || $chevron3 == $chevron2) { $chevron3 = rand(1,39); $c3 = 0; }else{ ++$c3; }} $chevron4 = rand(1,39); $c4 = 0; while ($c4 < 1) { if ($chevron4 == $chevron1 || $chevron4 == $chevron2 || $chevron4 == $chevron3) { $chevron4 = rand(1,39); $c4 = 0; }else{ ++$c4; }} $chevron5 = rand(1,39); $c5 = 0; while ($c5 < 1) { if ($chevron5 == $chevron1 || $chevron5 == $chevron2 || $chevron5 == $chevron3 || $chevron5 == $chevron4) { $chevron5 = rand(1,39); $c5 = 0; }else{ ++$c5; }} $chevron6 = rand(1,39); $c6 = 0; while ($c6 < 1) { if ($chevron6 == $chevron1 || $chevron6 == $chevron2 || $chevron6 == $chevron3 || $chevron6 == $chevron4 || $chevron6 == $chevron5) { $chevron6 = rand(1,39); $c6 = 0; }else{ ++$c6; }} $address = "$chevron1 - $chevron2 - $chevron3 - $chevron4 - $chevron5 - $chevron6"; } generate(); echo $address; Hi all, i think i am making a really stupid mistake but i have a problem with my php function that i do not get. My function is: Code: [Select] function user_level($userlevel){ if($userlevel = 0){ $level = test; } elseif($userlevel >= 1){ $level = test1; } return $level; } In the cases i tried it on the userlevel is way higher than 1, but nothing returns when i echo the function. Whenever i change the >= to = and the exact number, it works fine. So the following does work: Code: [Select] elseif($userlevel = 767){ $level = test1; } Am i doing something really stupid here? :p Hello, Basically, I'm using srand to generate a number, and if the user gets a specific number, they can win by entering their details into the form. However, I want to block other numbers except from (in this example) 300000. I'm using: <form method="POST" id="form1" name="form1" action="send.php"> Email:<input type="text" id="name" name="email"><br /> <input type="hidden" value="<?php echo $b ?>" name="name" id="name" /> <input type="hidden" value="<? echo $random_number ?>" name="code" id="code" /> <br /><input type="submit" name="submit" value="Submit my code"> </form> With: <?php session_start(); if($_SERVER['REQUEST_METHOD'] === 'POST'){ if(isset($_POST["code"]) && $_SESSION["code"] == $_POST["code"]) { $blacklisted = Array("300000", "##", "##", "##", "##", "##"); $code = $_POST['code']; if( !in_array( strtolower($code), $blacklisted ) ) { $emailblock = '<div id="captchatext">Sorry, that number was not 300000.</div>'; } else { require('send.php'); } }} ?> However, any number entered seems to require send.php. Many thanks Can someone help me create this?? Upon outside entry, a random number is chosen between 1 and 10. Use this function to generate the guess number $guessnum = rand(1,10); // you may change the variable name The user tries to guess this number by choosing from a selection list of possibilities. The user "loses" if there are three failed attempts. For reentrant activations the selection list must be sticky and the same guess number must be maintained. The guess number and the attempt number must both be propagated through hidden inputs. Here is a screen shot: Upon outside entry, or using the "Start Over" hyperlink (with the list activated): Let's suppose the number to be guessed is 6. I select 4 and guess it. Response should say "Try #1" I select 9 and guess it. Response should say "Try #2" I select 3 and guess it. Response should say "You Lose" At this point assume that we must "Start Over". This time, suppose the generated number is 8. I select 8 and guess it. Response should say "You Win" Again, assume we must "Start Over". |