Jump to content

PaulRyan

Members
  • Posts

    876
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by PaulRyan

  1. You need to post all of your code, posting a snippet doesn't really help us gauge the problem.
  2. Then there is your answer, look the errors up and you should be good to go.
  3. Turn of full error reporting: <?PHP error_reporting(E_ALL); ini_set("display_errors", 1); ?> Also, this line: if(!$_POST['username'] | !$_POST['pass']) { Should be: if(!$_POST['username'] || !$_POST['pass']) {
  4. You want to display ">"? You use htmlentities when display the data to the user. Take this for example: <?PHP $HTML = '<span> THIS IS HTML </span>'; echo 'Will not display ">" - '. $HTML; echo '<br> ------------------------- <br>'; echo 'Will display ">" - '. htmlentities($HTML); ?>
  5. You are to return the data via mysql_fetch_assoc or mysql_fetch_array
  6. Ohh right, well you need to create a new session variable something like "$_SESSION['numbers_guessed']" and then add each guessed number that is wrong to that variable. Look into array for that. Displaying amount of guesses I explained in my previous post, use the variable "$_SESSION['guesses']" I did the hard work, now have a little try to see what you can do, and pop back with any questions
  7. Use the session variable 'guesses' to display how many guesses. I won't be able to give my e-mail address out, but you can always post here if you have problems, there's always someone around to help/
  8. Was bored, so I gave this a little go. Try this: <?PHP session_start(); #session_destroy(); //### Current file name $filename = basename($_SERVER['PHP_SELF']); //### If play is set, reset all values if(isset($_GET['play'])) { unset($_SESSION['number']); unset($_SESSION['guesses']); unset($_SESSION['guessed']); } //### Start the output $output = ''; //### Check if the form is posted if($_SERVER['REQUEST_METHOD'] == 'POST') { //### Set the number that was guessed $numberGuessed = isset($_POST['numberGuessed']) ? (int)$_POST['numberGuessed'] : FALSE ; //### If no number is guessed, display error if(empty($numberGuessed)) { $output .= 'Please enter a number to guess. <br>'; //### Validation passed } else { //### Increment guesses $_SESSION['guesses']++; //### Check to make sure they have guesses available if($_SESSION['guesses'] <= 7) { //### check if they guessed the secret number if($numberGuessed == $_SESSION['number']) { $_SESSION['guessed'] = TRUE; //### check if the number is lower than the secret number } else if($_SESSION['number'] < $numberGuessed) { $output .= 'Bad luck! The number is lower. <br>'; //### Else the number is higher } else { $output .= 'Bad luck! The number is higher. <br>'; } } } } //### Set the secret number and amount of guesses $_SESSION['number'] = isset($_SESSION['number']) ? $_SESSION['number'] : mt_rand(1,10) ; $_SESSION['guesses'] = isset($_SESSION['guesses']) ? min($_SESSION['guesses'], 7) : 0 ; //### Debug purposes echo '<pre>'; print_r($_SESSION); echo '</pre>'; //### Check if the secret number has been guessed if(isset($_SESSION['guessed'])) { $output .= 'Well done! You guessed the number. <br>'; $output .= '<a href="'.$filename.'?play=true">Play again?</a>'; //### Check if they have used all of their guesses } else if($_SESSION['guesses'] >= 7) { $output .= 'You used up all your guesses. <br>'; $output .= 'The secret number was: '. $_SESSION['number'] .'. <br>'; $output .= '<a href="'.$filename.'?play=true">Play again?</a>'; //### If both checks passed, show form } else { $output .= '<form method="POST" action="'. $filename .'"> Your Guess: <input type="text" name="numberGuessed"> <input type="submit" value="Submit Guess"> </form>'; } echo $output; ?>
  9. When outputting the data, use nl2br to convert line ending characters to new lines. Take this for example: <?PHP $string = "This is a string. \r\n This is on a new line."; echo 'Without nl2br() <br> "'. $string.'"'; echo '<br>---------------------------<br>'; echo 'With nl2br() <br> "'. nl2br($string) .'"'; ?>
  10. Glad you fixed your issue, next time explain your problem better and we'll be able to offer better advice/help.
  11. I think I decoded what he means <?PHP if(!empty($row['skill3link']) && !empty($row['skill3'])) { //### Echo content here } ?> *Edit: Why do you keep jumping in and out of the PHP tags? That looks really messy, and is quite hard to follow.
  12. What are you expected results? What are your current results? What should the output look like?
  13. This is something I put together: <?PHP //### Start the session session_start(); //### File name $filename = basename($_SERVER['PHP_SELF']); //### Assign $_GET variables if they exist $itemID = isset($_GET['id']) ? (int)$_GET['id'] : FALSE ; $action = isset($_GET['action']) ? $_GET['action'] : FALSE ; $subAction = isset($_GET['sub_action']) ? $_GET['sub_action'] : FALSE ; //### Add item to the items array, if it doesn't already exist if($action == 'add') { if(!isset($_SESSION['cart']['items'][$itemID])) { $_SESSION['cart']['items'][$itemID] = 1; } header('Location: '. $filename); exit; } //### Increase item count, if the item exists //### Decrease item count, if the item exists //### If the item count equals 1, remove the item from the item array if($action == 'update') { if($subAction == 'add') { if(isset($_SESSION['cart']['items'][$itemID])) { $_SESSION['cart']['items'][$itemID]++; } } else if($subAction == 'remove') { if(isset($_SESSION['cart']['items'][$itemID])) { if($_SESSION['cart']['items'][$itemID] > 1) { $_SESSION['cart']['items'][$itemID]--; } else { header('Location: '. $filename .'?action=delete&sub_action=item&id='. $itemID); exit; } } } header('Location: '. $filename); exit; } //### Delete item from item array, if it exists //### Delete all items from item array if($action == 'delete') { if($subAction == 'item') { if(isset($_SESSION['cart']['items'][$itemID])) { unset($_SESSION['cart']['items'][$itemID]); } } else if($subAction == 'cart') { $_SESSION['cart']['items'] = array(); } header('Location: '. $filename); exit; } echo '<pre>'; print_r($_SESSION); echo '</pre>'; for($i=1; $i<=5; $i++) { echo '<a href="?action=add&id='.$i.'">Add Item '.$i.'</a> - '; echo '<a href="?action=update&sub_action=add&id='.$i.'">Update Item '.$i.'</a> - '; echo '<a href="?action=update&sub_action=remove&id='.$i.'">Remove Item '.$i.'</a> - '; echo '<a href="?action=delete&sub_action=item&id='.$i.'">Delete Item '.$i.'</a>'; echo '<br>'; } echo '<a href="?action=delete&sub_action=cart">Delete Cart</a>'; ?>
  14. You need a separate form for each item. With the code you have, all they items are in one form, and the browser will send the last value of "delItem", which is the value of the last item in the cart.
  15. Show us what you have attempted? We won't code for you, but we can help you achieve what you want with some guidance.
  16. Replace line 18 with this: $time = date('F d, Y g:i:sa',time());
  17. Barand, thanks for pointing that out. I just assumed that is what happened, I've had magic_quotes on all along it seems, must have forgotten to turn them off with my new install on my computer.
  18. That what escaping data does, you have to remove it via stripslashes when outputting to the end user.
  19. My mistake, pasted into the wrong sections.
  20. I totally missed this, I don't know how I manage to do that. Davey pointed out the error for the final div closing, kudos.
  21. Both answers lacked a check if the results are not a multiple of 4. If you put 13 results, you get an open div round the last result, but not a closing one. Try this: <?PHP $num = 0; $output = ''; foreach($db_res as $value) { $num++; //### Open div if($num%4==1) { $output .= '<div>'; } //### Add value to output $output .= $value; //### Close div if($num%4 == 0) { $output .= '</div>'; } } //### If total results is not multiple of 4, close the final div if($num%4 != 0) { $output .= '</div>'; } //### Display output echo $output; ?>
  22. You shouldn't jump in and out of PHP tags like that, it makes for messy code. Try this: <?PHP if($highname1 == 'open') { $output = '<div class="module high open"> <img src="Icon_hi_slot.png" width="46" height="46"> </div>'; } else if(strlen(trim($highname1))) { $output = '<div class="module high inactive"> </div>'; } else { $output = '<div class="module high" data-typeid=$high1typeID data-name=$high1name> <img src="http://image.website.com/Type/'. $high1typeID .'_64.png"> </div>'; } echo $output; ?>
  23. Shouldn't "UPPER(player_bans)" in fact be "UPPER(name)"?
×
×
  • 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.