Jump to content

Tenaciousmug

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by Tenaciousmug

  1. It's only displaying the first result and not the others. What am I doing wrong? I'm selecting the items the user occupies. Then I'm selecting the name and image of that item from the item table. echo "<table cellspacing=\"0\" class=\"news\" align=\"center\">"; echo "<tr>"; $sql = "SELECT * FROM useritems WHERE userid='".$_SESSION['userid']."' LIMIT $offset, $rowsperpage"; //selects all the users items to whoever is logged in $result = mysqli_query($cxn,$sql) or die(mysqli_erro($cxn)); $imagecount = 0; while ($row = mysqli_fetch_assoc($result)) //while there are still results { extract($row); $quantity = $row['quantity']; $itemid = $row['itemid']; $sql = "SELECT * FROM items WHERE itemid='".$itemid."'"; //selecting the name and image of the item that is displaying $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); $row = mysqli_fetch_assoc($result); $name = $row['name']; $image = $row['image']; if ($imagecount%5 == 0) //after 5 items have been listed, start a new line { echo "</tr>"; echo "<tr>"; } } echo "<td width=\"120px\" align=\"center\">"; echo "<img src=\"http://www.elvonica.com/".$image."\"><br>"; echo $name." (".$quantity.")"; echo "</td>"; $imagecount++; //after one item has been displayed, redo the loop if there are still results } echo "</table>";
  2. This code will not insert OR update. But on the other ones it will.. but for this one, I'm doing an extra step to say that they can claim the item or not. From adding that extra step, it won't insert or update. $rand = rand(1,3); if ($rand == 1) { $rand = rand(1,3); if($rand == 1) { $sql = "SELECT * FROM randomevents WHERE rarity = '1'"; $result = mysqli_query($cxn, $sql); while ($row = mysqli_fetch_assoc($result)) { $event[] = $row['phrase']; } //This will pick a random event and show it $renum = rand(0,count($event)-1); $display = $event[$renum]; if ($display == "") { $eventdisplay = ""; } else { $sql = "SELECT * FROM randomevents WHERE phrase='".mysqli_real_escape_string($cxn,$display)."'"; $result = mysqli_query($cxn, $sql) or die("Query died: select everything from randomevent table"); $row = mysqli_fetch_array($result); $itemid = $row['itemid']; $image = $row['image']; if ($row['type'] == "itemgain") { $sql2 = "SELECT name, image FROM items WHERE itemid='".$itemid."'"; $result2 = mysqli_query($cxn, $sql2) or die(mysqli_error($cxn)); $row2 = mysqli_fetch_assoc($result2); $itemname = $row2['name']; $itemimage = $row2['image']; $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$display."</center></p> <p> <form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"post\"> <input type=\"submit\" name=\"claimitem\" value=\"Claim Egg!\" /> </form> </p> </td> </table><br>"; if (isset($_POST['claimitem'])) { $sql = "SELECT * FROM useritems WHERE itemid='".$itemid."' AND userid='".$_SESSION['userid']."'"; $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); $num = mysqli_num_rows($result); if ($num == 0) { $sql = "INSERT INTO useritems (userid, itemid, name, image, quantity) VALUES ('".$_SESSION['userid']."', '".$itemid."', '".$itemname."', '".$itemimage."', '1')"; mysqli_query($cxn, $sql) or die("Query died: insert for itemgain"); } else { $sql = "UPDATE useritems SET quantity = quantity+1 WHERE itemid='".$itemid."' AND userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: update for itemgain"); $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$display."</center></p> </td> </table><br>"; } } } } } }
  3. Thank you! I fixed it. (: There was an error_logs.html or something and I viewed it and it was something with the randomevents.php on the 3rd line. So I just deleted the page and redid it and it worked. xP
  4. It just says under my main error logs: I have no clue how to fix this.. so I won't even be able to use my site now?
  5. 500 Server Error A misconfiguration on the server caused a hiccup. Check the server logs, fix the problem, then try again. What does this mean? Does it mean their server is down or what? It was just working for me this morning. It's seeming like it's my fault, but I didn't even touch any of the pages since then.
  6. Wow, you're a genius. (: It's because the first phrase for receiving starpoints had an apostrophe. And the other one didn't. That's why that one was showing. Thank you so much! (:
  7. I did that. It does the same thing. They're basically the same.
  8. Crap nevermind. Now I'm getting an error whenever its wanting to show the "youve gained starpoints" random event. <?php include("config.php"); //To change the odds, change the second number in the rand() function. $rand = rand(1,3); if($rand == 1) { $sql = "SELECT * FROM randomevents WHERE rarity <= '10'"; $result = mysqli_query($cxn, $sql); while ($row = mysqli_fetch_assoc($result)) { $event[] = $row['phrase']; } //This will pick a random event and show it $renum = rand(0,count($event)-1); $display = $event[$renum]; if ($display == "") { $eventdisplay = ""; } else { $sql = "SELECT * FROM randomevents WHERE phrase='".$display."'"; $result = mysqli_query($cxn, $sql); $row = mysqli_fetch_array($result); $image = $row['image']; if ($row['type'] == "gainsp") { $rand = rand(200,500); $displaya = str_replace("rand", "".$rand."", "".$display.""); $sql = "UPDATE members SET starpoints = starpoints+$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$displaya."</center></p> </td> </table><br>"; } elseif ($row['type'] == "losesp") { $rand = rand(50,100); $displaya = str_replace("rand", "".$rand."", "".$display.""); $sql = "UPDATE members SET starpoints = starpoints-$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$displaya."</center></p> </td> </table><br>"; } else {} } } else { $eventdisplay = ""; } ?> Error message:
  9. Well I got it doing it another way. Pretty long, but I don't feel like confuzzling my brain anymore. xD I put: if ($row['type'] == "gainsp") { $rand = rand(200,500); $displaya = str_replace("rand", "".$rand."", "".$display.""); $sql = "UPDATE members SET starpoints = starpoints+$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$displaya."</center></p> </td> </table><br>"; } elseif ($row['type'] == "losesp") { $rand = rand(50,100); $displaya = str_replace("rand", "".$rand."", "".$display.""); $sql = "UPDATE members SET starpoints = starpoints-$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$displaya."</center></p> </td> </table><br>"; } Thanks though! (:
  10. Oh wow. You have any clue how I would do that? Sorry, my brain is completely dead and I can't even think of where to start on that one. But thanks for the.. further solution. xP
  11. Wow the smallest things. (: Thank you so much! Very much appreciated. <3
  12. It's working great, but at some points after one of the random events goes through, I reload the page and it either gives me or takes away some starpoints without showing the message.. but it shows the message all the other times. Could someone help me debug this and see why it's doing that? <?php include("config.php"); //To change the odds, change the second number in the rand() function. $rand = rand(1,3); if($rand == 1) { $sql = "SELECT * FROM randomevents WHERE rarity <= '10'"; $result = mysqli_query($cxn, $sql); //Write the events in here with the opener: $event[] = "#your event#"; while ($row = mysqli_fetch_assoc($result)) { $event[] = $row['phrase']; } //This will pick a random event and show it $renum = rand(0,count($event)); $display = $event[$renum]; if ($display == "") { $eventdisplay = ""; } else { $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"><br> <tr><br> <td><center><b><h1>Random Event</h1></b></center></td><br> </tr><br> <tr><br> <td><img src=\"".$_SERVER['SCRIPT_NAME']."\"> <p><center>".$display."</center></p><br> </td><br> </table><br>"; $sql = "SELECT type FROM randomevents WHERE phrase='".$display."'"; $result = mysqli_query($cxn, $sql); $row = mysqli_fetch_assoc($result); if ($row['type'] == "gainsp") { $rand = rand(200,500); $sql = "UPDATE members SET starpoints = starpoints+$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); } elseif ($row['type'] == "losesp") { $rand = rand(50,100); $sql = "UPDATE members SET starpoints = starpoints-$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); } else {} } } else { $eventdisplay = ""; } ?>
  13. Isn't onclick part of Javascript? Do you have even have a javascript function in there to call that onclick?
  14. Try this: $matchlink = "onclick=\"location.href=\"".$match_link."\"";
  15. Alright, I have a random thing going on. Works perfectly fine. This is the code: <?php include("config.php"); //To change the odds, change the second number in the rand() function. $rand = floor(rand(0,1)); if($rand == 1) { $sql = "SELECT * FROM randomevents WHERE rarity <= '10'"; $result = mysqli_query($cxn, $sql); while ($row = mysqli_fetch_assoc($result)) { $event[] = $row['phrase']; if ($row['type'] == 'gainsp') { $rand = rand(200,500); $sql = "UPDATE members SET starpoints = starpoints+$rand WHERE userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: updating starpoints"); } } //This will pick a random event and show it $renum = floor(rand(0,count($event))); $eventdisplay = $event[$renum]; } ?> In the database, I have the phrases set as: "You have gained {$rand} starpoints!". How do you make that variable echo out as the $rand I'm generating on this page? It just keeps posting as is. When I went the {$rand} to display as the number I'm generating to set their starpoints to. So I guess how do you hold a variable in the database? Does anyone understand what I'm asking? Here as an image to help understand:
  16. OMG! Thank you sooo much! That's the spot I kept looking at. I guess I just need a second pair of eyes sometime. Genius. WONDERFUL. (:
  17. No it just refreshes the page. I do notice that it's putting all the attributes up in the URL. I mean it's reading them perfectly fine. But whenever I hit submit, it doesn't actually follow the if (isset($_POST['submit'])) I have going on. I took away that whole IF statement and it does the same thing. So I know it's not reading the submit button. I just don't get why it's not because last night, it was. :/ And I'm looking at my old books and I have everything correct...
  18. Whenever I hit the submit button, it's not even reading if they hit it and doing all that if and else statements I have. Why is not noticing the submit button? I had this working last night, but my dumb self saved over it with another file I was editing. <?php session_start(); include("config.php"); include("logincheck.php"); $time = date_default_timezone_set("US/Eastern"); $timeformat = date("Y-m-d H:i:s"); $author = $_SESSION['username']; $title = $_POST['title']; $body = $_POST['body']; if (isset($_POST['submit'])) { if (!empty($title)) { if (!empty($body)) { $sql = "INSERT INTO news (author, title, body, time) VALUES ('$author', '$title', '$body', NOW())"; mysqli_query($cxn, $sql); $error = "Your news posting has been submitted successfully."; } else { $error = "You must fill out the body of the posting!"; } } else { $error = "You must fil out the title of the posting!"; } } $sql = "SELECT userlevel FROM members WHERE userid='".$_SESSION['userid']."'"; $result = mysqli_query($cxn, $sql); $row = mysqli_fetch_array($result); if ($row['userlevel'] != 2) { $error = "You do not have the power to view this page!"; header("Location: news.php"); } else { ?> <?php include("header.php"); ?> <h1>Post News</h1> <?php echo $error; ?> <form method="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"> <b>Author:</b> <?php echo $author; ?><br> <b>Title:</b><br> <input type="text" maxlength="25" name="title" value="<?php echo $title; ?>" /><br> <b>Body:</b><br> <textarea name="body" maxlength="999" rows="10" cols="40"><?php echo $body; ?></textarea><br> <input type="submit" name="submit" value="Post News" /> </form> <?php } ?> <?php include("footer.php"); ?>
  19. Oh I had no clue when you used md5, 25 characters was too short. Thank you so much guys. <3
  20. <?php header("Location: URLHERE"); ?>
  21. I have it set as VARCHAR(25). But it's posting 32 characters. I have no clue why. I got this login thing to work a long time ago when I was first coding PHP.
  22. Ah. It's catching the username just fine, but it's adding 7 extra characters onto my password. It's suppose to be this: 7da293f88d6e3bffc85a5e86e And it's coming out like this: 7da293f88d6e3bffc85a5e86ee836fca Do you have any clue why it is doing that?
  23. Here is my code for the login script. Everything works perfectly, but everytime I enter everything CORRECTLY into the forum, it says "The username, ____, and password do not match!". When they do match. If I leave the areas blank, they say "You must enter a username!" or "You must enter a password!". All the error messages work good, but whenever I fill the form in correctly, it displays my first error message "The username, ____, and password do not match!". Does anyone see what's wrong with it? <?php session_start(); include("config.php"); $username = $_POST['username']; $usernamefinal = ucfirst(strtolower($username)); $password = $_POST['password']; if (isset($_POST['submit'])) { if(!empty($username)) { if (!empty($password)) { $sql = "SELECT username FROM members WHERE username='$usernamefinal'"; $result = mysqli_query($cxn, $sql) or die("Query died: username"); $num = mysqli_num_rows($result); if ($num > 0) { $sql = "SELECT username, password FROM members WHERE username='$usernamefinal' AND password=md5('$password')"; $result = mysqli_query($cxn, $sql) or die("Query died: username and password"); $num = mysqli_num_rows($result); if ($num > 0) { $sql = "SELECT userid FROM members WHERE username='$usernamefinal'"; $result = mysqli_query($cxn, $sql) or die("Query died: userid"); $row = mysqli_fetch_array($result); $userid = $row['userid']; $_SESSION['auth'] = "yes"; $_SESSION['username'] = $usernamefinal; $_SESSION['userid'] = $userid; $ipadd = $_SERVER['REMOTE_ADDR']; $sql2 = "INSERT INTO login (userid, username, logintime, ipadd) VALUES ('$userid', '$usernamefinal', NOW(), inet_aton('$ipadd'))"; mysqli_query($cxn, $sql2) or die("Query died: login session"); header("Location: news.php"); } else { $error = "The username, $usernamefinal, and password do not match!"; } } else { $error = "That username doesn't exist!"; } } else { $error = "You must enter a password!"; } } else { $error = "You must enter a username!"; } } ?> <?php include("header.php"); ?> <h1>Login Form</h1> <?php echo $error; ?> <form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br> <input type="submit" name="submit" value="Login"> </form> <?php include("footer.php"); ?>
  24. Here is my select statement: $sql = "SELECT date FROM sixdice WHERE username='$username'"; I'm trying to select the date from the game I'm creating to see if that user already rolled the dice today. Ok this is what I have: <?php include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $sql = "SELECT date FROM sixdice WHERE username='$username'"; $result = mysqli_query($cxn,$sql) or die("Couldnt find username"); $row = mysqli_fetch_array($result); if($row['date'] == now()); { echo "<br><br><form action='sixdice.php?roll' method='post'> <input type='submit' name='continuesix' value='Continue Game' /> </form>"; }else { echo "<br><br><form action='sixdice.php?roll' method='post'> <input type='submit' name='playsix' value='Play!' /> </form>"; }?> It's giving me this error: " Parse error: syntax error, unexpected T_ELSE in /home2/asterock/public_html/sixdice.php on line 25" Which is this line: }else EDIT Also, doesn't the now() function select the time as well? I only want to select today's DATE. Not the time too.
×
×
  • 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.