Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Everything posted by wildteen88

  1. Do you mean it is not updating your database? I have tested your function and can confirm it does add points when you win and takes points when you loose. If you create a new file and add this code in it <?php function bet ($bet, &$user){ //sleep(2); //$user1 = mysql_query("SELECT * FROM `users` WHERE `id`='" . $_SESSION['id'] . "'"); //$user = mysql_fetch_object($user1); $chance = rand (1, 2); $bet = round ($bet); $betPretty = number_format ($bet); if ($bet == 0) { $echo = "You did not bet anything!"; $chance = 0; } if ($bet < 0) { $echo = "You cannot bet a negative number."; $chance = 0; } if ($bet > $user->minigame_points) { $echo = "This is more minigame points than you have!"; $chance = 0; } if ($user->minigame_points == 0) { $echo = "You do not have any minigame points."; $chance = 0; } if ($chance == 1) { //Win $money = $user->minigame_points+$bet; $times_bet = $user->times_bet++; //mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'"); $money = number_format($money); $echo = "You won $betPretty minigame points!<br /><b>Current Minigame Points:</b> $money"; } if ($chance == 2) { //Lose $money = $user->minigame_points-$bet; $times_bet = $user->times_bet++; //mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'"); $money = number_format($money); $echo = "You lost $bet minigame points.<br /><b>Current Minigame Points:</b> $money"; } return $echo; } $user = new stdClass; $user->minigame_points = 100; $user->times_bet = 0; echo bet(10, $user); ?> All I did was comment your queries and hard coded in some dummy data to test the function with.
  2. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=332538.0
  3. Probably because you're trying to access an item from your array when defining ${$language}['succesfull login'] as global. You cannot defined an array item as global only variables can be defined as global. You should ideally pass your variables to your function rather than define them as global.
  4. As the query returns both the news and the comments. You will need to first extract the news article and then add all the comments into an array. Then where you want your comments to display you'll then use a foreach loop to output your comments.
  5. Isn't the AS keyword optional? I've never had any problems without it.
  6. I guess when you view a news entry your url is like site.com/news.php?id=1. Which displays the news article with the id of 1 from your news table. If thats the cause you can use a JOIN which will query both your news and newscomments table at the same time. Example join query. SELECT n.title, n.author, n.article, c.username, c.email, c.coment FROM news n LEFT JOIN newscomments c ON (c.News_ID = n.ID) WHERE n.ID = $news_id
  7. It seems you have a charset issue. How are you storing your text within your database?
  8. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=332527.0
  9. What happens when you go to display_pic.php do any errors appear?
  10. This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=332483.0
  11. A function I came with. function halfRound($num) { // round number to nearest tenth $wR = round($num, 1); // get the difference $dif = $wR - $num; // check difference if($dif < 0) $num = $wR + 0.05; // add 0.05 to rounded number elseif($dif > 0) $num = $wR - 0.05; // take 0.05 to rounded number return $num; } $array = array(0.11, 0.28, 0.71, 10002.71); foreach($array as $item) { echo "<p>$item rounded to " . halfRound($item) . "</p>"; }
  12. What is the contents of $row['name']?
  13. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=332473.0
  14. <!DOCTYPE html> has nothing to do with PHP. As you're using sessions I guess you have written your own session handler for saving your sessions to the database. When you call session_start() to create a session make sure you calling that function before any html has been sent to the web browser. If you call it after html has been sent session will no longer work.
  15. The www. bit is optional that is what the question mark represents after the www\. part. I'm no regex expert but yea I guess it should work for you.
  16. The problem is to with your regex pattern. If the url is www.test.com.net The first bit ^($label) which is expanded to ^([\\w][\\w\\.\\-]{0,61}[\\w]) Is matching www.test.com. And the second part to your pattern \\.($tld_s), which is expanded to \\.(com|net|org|co\.uk) Is matching the .net part of your url. So the problem your first pattern is being too greedy. You'll need to modify it so it doesn't match your tlds. I have came up with a different pattern to try. For $label set it to the following pattern www\.?([\w-]+){0,61}.
  17. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=332465.0
  18. I maybe wrong but wouldn't it be easier to implode your $tld_list array into your pattern using the pipe character as a the separator. That way preg_match will only match the urls that contain the tlds within your array. $label = '[\\w][\\w\\.\\-]{0,61}[\\w]'; $tld_list = array('com', 'net', 'org', 'co.uk', 'mobi'); $tld_s = implode('|', array_map('preg_quote', $tld_list)); foreach($lines as $line) { // check that each line/domain is in the valid format, else return an error for each domain if(preg_match( "/^($label)\\.($tld_s)$/", $line, $match ))
  19. Why have diffident databases for comments? You're better of storing your comments within a table called comments that is in your main database.
  20. Because you have missed of the comma in str_replace Notice the highlighted comma.
  21. Your code is not syntactically valid at all. All text/html you want to be outputted should be wrapped in quotes not curly braces as violinrocker demostrated. <?php if ($_GET=='') { echo '<form name="input" action="http://www.xxx.uk/index.php?name=ro" method="post"> Enter student number:<input type="text" name="sid"/> <input type="submit" value="Submit">" </form>'; } elseif ($_GET=='ro') { echo "the really long content that you want in here"; } ?>
  22. What are you wanting to with the session id when your destroy the session. The id will never be unset, session_id will always return the id of the current active session, even after calling session_destroy.
  23. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=332434.0
  24. session_destroy() only erases the data stored within the current active session. If you want a new session id to be generated when the user logs out you'll need to use session_regenerate_id.
  25. You are not making any sense at all. Please explain what you are trying to do. Are you trying to set a cookie so it stores an email address?
×
×
  • 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.