Jump to content

ryeman98

Members
  • Posts

    286
  • Joined

  • Last visited

    Never

Everything posted by ryeman98

  1. Glad to get back in the game, I haven't programmed php for months!
  2. Obviously. Who's fault did you think it would be? Yours.
  3. Fixed, turns out it was just a mistake on my part.
  4. Ok. Say there are 3 different items in a form. Once they're sent to process, the loop will go through each item and change their prices accordingly. What's happening is that it's taking the last price (each item is a different price) and changing them all to that price. What it needs to do is change each price separately but I can't figure out how to connect the item to the price.
  5. That really doesn't do anything. Item is a string and price is an integer.
  6. So I've got a shop and I need it to update multiple item prices at once but can't figure out how to connect the proper item to the proper price: Form: echo "<form action='yourshop.php?act=changeprices' method='post'>"; echo "<input type='hidden' name='shop_id' value='".$shop_id."'>"; echo "<table align='center' width='100%' border='0' cellspacing='0' cellpadding='2'>"; echo "<tr bgcolor='#000066' style='color:#FFFFFF;'><th width='20%'>Item</th><th width='5%'>QTY</th><th width='20%'>Name</th><th width='40%'>Description</th><th width='10%'>Price</th><th width='5%'>Remove</th></tr>"; while ($row2 = mysql_fetch_array($items)) { $itemname = $row2['item']; $item_info = mysql_query("SELECT `description` FROM `items` WHERE name='$itemname'"); $item = mysql_fetch_array($item_info); echo "<tr bgcolor='#CCCCCC'>"; echo "<td><img style='border: 1px solid #000000;' src='../images/items/".strtolower($row2['item']).".gif'></td>"; echo "<td>".$row2['COUNT(item)']."</td>"; echo "<td><input type='hidden' name='item[]' value='".$row2['item']."'>".$row2['item']."</td>"; echo "<td>".$item['description']."</td>"; echo "<td><input type='textbox' name='price[]' size='7' maxlength='9' value='".$row2['price']."' /></td>"; echo "<td><input type='checkbox' name='remove[]' value='".$row2['item']."' /></td>"; echo "</tr>"; } echo "<tr bgcolor='#000066' style='color:#FFFFFF;'><td colspan='6'><input type='submit' value='Update Shop'></td></tr>"; echo "</table>"; echo "</form>"; Process foreach ($_POST['item'] as $item) { foreach($_POST['price'] as $price) { $update = mysql_query("UPDATE `ushop_items` SET `price`='$cost' WHERE shop_id='$shop_id' AND item='$item'"); } // End loop } // End loop
  7. http://www.w3schools.com/php/default.asp
  8. Alright, I'll just post the whole thing. It's a little messy tho <?php ob_start(); session_start(); $username = $_COOKIE['username']; include_once("../includes/config.php"); // GLOBAL VARIABLES $global_id = 4; $games = mysql_query("SELECT * FROM `games` WHERE id='$global_id'"); $global_row = mysql_fetch_array($games); $global_name = $global_row['name']; $global_image = $global_row['img_url']; $global_cost = $global_row['cost']; $global_max_prize = $global_row['max_prize']; $global_description = $global_row['description']; // END GLOBAL VARIABLES if ($_GET['act'] == "sessions") { session_destroy(); $_SESSION['bust_pageview'] = 0; $_SESSION['bust_prize'] = $global_cost; $user_eP = mysql_query("SELECT ePoints FROM `users` WHERE username='$username'"); $row = mysql_fetch_array($user_eP); $new_eP = $row['ePoints']-$global_cost; if ($row['ePoints'] < $global_cost) { header('Location: bust.php?act=notenough'); } else { $update = mysql_query("UPDATE `users` SET ePoints='$new_eP' WHERE username='$username'"); header('Location: bust.php?act=choose'); } // End if } elseif ($_GET['act'] == "resetsess") { $_SESSION['bust_pageview'] = 0; header('Location: bust.php?act=choose'); } // End if $pagetitle = "Errion - ". $global_name .""; include("../includes/header.php"); include("../includes/randomevents.php"); include("../includes/checklogin.php"); ?> <h2>Double or Bust!</h2> <?php if ($_GET['act'] == "choose") { echo $_SESSION['bust_pageview']; echo $_SESSION['bust_prize']; echo "<b>Current Pot:</b> ". $_SESSION['bust_prize'] ." ePoints"; echo "<form action='bust.php?act=result' method='post'>"; echo "<table align='center' width='20%' border='0'><tr><td align='center'>"; echo "<input type='radio' name='choice' value='heads'><br />Heads"; echo "</td><td align='center'>"; echo "<input type='radio' name='choice' value='tails'<br />Tails"; echo "</td></tr></table>"; echo "<div align='center'><input type='submit' value='Double or Bust!'></div>"; echo "</form>"; } elseif ($_GET['act'] == "result") { $_SESSION['bust_pageview'] = $_SESSION['bust_pageview']+1; if ($_SESSION['bust_pageview'] > 1) { echo "<a href='/rules.php'>No cheating!</a>"; } else { $user_choice = $_POST['choice']; $comp = array("heads", "tails"); $rand_comp = rand(0, 1); $comp_choice = $comp[$rand_comp]; echo "You chose: ". $user_choice ."<br />"; echo "The correct answer is: <b>". $comp_choice ."</b><br /><br />"; function userWin() { $_SESSION['bust_prize'] = $_SESSION['bust_prize']*2; echo "You win! You can keep playing or take your money.<br />"; echo "The pot is now at: ". $_SESSION['bust_prize'] ." ePoints<br /><a href='bust.php?act=resetsess'>Continue</a><br /><a href='bust.php?act=collect'>Collect your winnings!</a>"; } // End function function userLoss() { $_SESSION['bust_prize'] = 0; echo "You lose all of the money in the pot!<br /><a href='/games/game.php?id=".$global_id."'>Play Again?</a>"; } // End function if ($user_choice == "heads" && ($comp_choice == "heads")) { userWin(); } elseif ($user_choice == "tails" && ($comp_choice == "tails")) { userWin(); } elseif ($user_choice == "heads" && ($comp_choice == "tails")) { userLoss(); } elseif ($user_choice == "tails" && ($comp_choice == "heads")) { userLoss(); } else { echo "There is a problem with the game. Please report this error!"; } // End result check } // End if } elseif ($_GET['act'] == "collect") { $_SESSION['bust_pageview'] = $_SESSION['bust_pageview']+1; $prize = $_SESSION['bust_prize']; $user_info = mysql_query("SELECT ePoints FROM `users` WHERE username='$username'"); $row = mysql_fetch_array($user_info); $new_eP = $row['ePoints']+$prize; $month = date("F"); // Highscores $check_user_score = mysql_query("SELECT * FROM `highscore_bust` WHERE username='$username'"); $row2 = mysql_fetch_array($check_user_score); if ($prize == 0) { echo "You didn't make the highscores, sorry!<br /><br />"; } elseif (!$row2['username']) { $insert_score = mysql_query("INSERT INTO `highscore_bust` (username, score, month) VALUES ('$username', '$prize', '$month')"); } elseif ($row2['score'] <= $prize) { $update_score = mysql_query("UPDATE `highscore_bust` SET score='$prize', month='$month' WHERE username='$username'"); } // End Highscores if ($_SESSION['bust_pageview'] <= 2) { $update = mysql_query("UPDATE `users` SET ePoints='$new_eP' WHERE username='$username'"); } echo "You won ". $prize ."eP! <a href='bust.php'>Play Again?</a>"; } elseif ($_GET['act'] == "notenough") { echo "Sorry, you don't have enough eP to play this game!"; } else { echo "<table width='60%' border='0'>"; echo "<tr><td align='left' valign='top'><img align='left' src='". $global_image ."' /></td><td align='left'><b>Cost:</b> ". $global_cost ."eP<br /> <b>Max. Prize:</b> ". $global_max_prize ."<br /> <a href='highscores.php?gameid=". $global_id ."'>Highscores</a></td></tr>"; echo "<tr><td></td><td align='left'>". $global_description ."<br /><br />"; echo "<form action='bust.php?act=sessions' method='post'><input type='submit' value='". $global_name ."' /></form></td></tr></table>"; } // End if ?> <?php include("../includes/footer.php"); ?>
  9. I hate posting this many times in a row but I've been playing around with it all day and can't get it to work ...
  10. If you need more info just let me know, this is pretty confusing.
  11. It is at the top and it's the exact order that my other game was in and the other game works just fine. No, it's only run before the game starts so that it clears the user's previous game sessions.
  12. Hey there, I'm making a game and in certain parts of the script the variables aren't working. I made a Rock, Paper, Scissors game and then just changed the script to make this one. The rps game works perfectly but this one is having problems. // GLOBAL VARIABLES $global_id = 4; $games = mysql_query("SELECT * FROM `games` WHERE id='$global_id'"); $global_row = mysql_fetch_array($games); $global_name = $global_row['name']; $global_image = $global_row['img_url']; $global_cost = $global_row['cost']; $global_max_prize = $global_row['max_prize']; $global_description = $global_row['description']; // END GLOBAL VARIABLES if ($_GET['act'] == "sessions") { session_destroy(); $_SESSION['bust_pageview'] = 0; $_SESSION['bust_prize'] = $global_cost; As you can see, it gets the info about the game from the db and then puts it into variables. Those variables get set but when it goes to bust.php?act=choose, the variables work fine. Once it goes to bust.php?act=result, the variables then become NULL for some reason. And to make matters worse, those Sessions there aren't being set at all. Any ideas? (Yes, I have session_start(); at the beginning of the script.)
  13. I don't know what's more sad ... your spelling and grammar or the fact that you have no idea what you're talking about.
  14. Hey there, I have a script where I need the date to be: date("Y-m-d") but have it go back exactly a week. I've tried a few things but I need the Y-m-d format for it to work.
  15. Two of those are if statments so it wouldn't make any sense.
  16. Are you serious? Get their ID or username or w/e and create a WHERE
  17. You'll have to make those lines so their not relying on register_globals being on. What? ???
  18. That doesn't have any where clause?? lol Put one in, I don't know what your table looks like
  19. Got this: /includes/header.php on line 48 Notice: Undefined index: css in /home/vol1/byethost13.com/b13_1141145/errion.byethost13.com/htdocs/includes/header.php on line 125 Notice: Undefined index: HTTPS in /home/vol1/byethost13.com/b13_1141145/errion.byethost13.com/htdocs/includes/header.php on line 9
  20. mysql_query("UPDATE `game_planets` SET `belcredits=belcredits+100");
  21. I'm using Dreamweaver 8 because I prefer that but I still code by hand with it. I don't like how it adds stuff for you at the click of a button.
  22. So there aren't any errors that pop up, it's just plain not working // SHOP RESTOCKING CRON $shops = mysql_query("SELECT * FROM `shops`"); $forward = time()+480; $res_time = date("F j - H:i"); // Current time $res_update_time = date("F j - H:i", $forward); // 8 minutes from now while ($shops_row = mysql_fetch_array($shops)) { $shop_id = $shops_row['id']; $restocks = mysql_query("SELECT * FROM `shop_restocking` WHERE shop_id='$shop_id'"); while ($restocks_row = mysql_fetch_array($restocks)) { $amount_items = $restocks_row['SUM(amount)']; // Total amount of items in the shop $i = $amount_items; if ($amount_items <= 5) { // If the amount of items equals 5 or less, continue if ($res_time >= $res_update_time) { // If the 8 minute wait is up, continue while ($i<=50) { // Loop while $i is less than 50 $restock_min = 1; $restock_max = $restocks_row['COUNT(id)']; $rand_num = rand($restock_min, $restock_max); // Picks a random number $res_check_id = mysql_query("SELECT * FROM `shop_restocking` WHERE item_id='$rand_num'"); // Check if the id exists if (!$res_check_id) { // If the id does not exist, do nothing } else { // If the id exists, continue $check_id_row = mysql_fetch_array($res_check_id); $rarity = $check_id_row['rarity']; // The item's rarity $amount = round($rarity/8); // The amount of items that will be entered $res_update = mysql_query("UPDATE `shop_restocking` SET amount='$amount' WHERE id='$rand_num'"); // Reset the amount } // End if $i=$i+$amount; } // End while } // End if } // End if } // End while } // End while So it works by checking the total amount of items in a shop. If there are less than 5 items, then the shop should wait 8 minutes and then be restocked. Then it just starts picking random items to put into the shop up until there are a total of at least 50 items.
  23. Not only am I wondering what's wrong with the above but will this work too? $amount = round($rarity/8); // The amount of items that will be entered
  24. Ok try this then: $sql = mysql_query("SELECT ban_ip FROM ban_ip WHERE ban_ip = '$client_ip'") or die('Error, query failed'); $row = mysql_fetch_array($sql);
×
×
  • 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.