Jump to content

Vel

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by Vel

  1. I was thinking about this and I had an epiphany this morning. The reason $_SESSION['username'] is empty is because you destroy the session before calling logout. You need to call logout then destroy the session.
  2. I PM'd you my e-mail address. Zip up all your files and I'll look through, see if I can find the error.
  3. Your welcome . I get a lot of help here too and like to give back when I can. The problem is there is nothing in $_SESSION['username']. Why, I can't tell without seeing all of your code. I suggest you start with session.php and go through to where $_SESSION['username'] should be set and see why it isn't being set.
  4. I copied your code and added the extra. For me Line 69 is "$sql = "UPDATE `users` SET logged_in = 0 WHERE username = '$username'";" Can you adding: echo "Session Username: " . $_SESSION['username'] . "<br>"; after line 69. See what that gives.
  5. OK, add ini_set ("display_errors", "1"); error_reporting(E_ALL); to the top of the page. then change your code to: <?php ... //set logged_in to ZERO on user //THIS WORKS IF I SET A SPECIFIC USERNAME...NEED TO PULL SESSION USERNAME SOMEHOW $username = $_SESSION['username']; $sql = "UPDATE `users` SET logged_in = 0 WHERE username = '$username'" if(!mysql_query($sql)) die('Error updating logged out user. ' . mysql_error() . '<br>SQL: ' . $sql); See if it outputs any error.
  6. Ah, OK. I thought you had posted the entire page. Shouldn't that be $_SESSION['username']?
  7. OK. Thanks for the information .
  8. You have to start the session every time you load a page. That's why I asked if the initial script you posted was run as an include or independent file. From what I can see from your code someone clicks the logout button and is then sent to the page you linked in your original post. Because it's a new page you need to start the session again.
  9. Yea, it's an independent page. I think the problem is you haven't started the session, therefore when you try $_SESSION['username'] it can't because the session isn't loaded. Add session_start(); to the top of your page and it should work.
  10. That's helpful, thank you . That covers getting the information I need out of the database nicely. However I'm also unsure what would be the best way to get the details displayed on a page to cycle every x seconds. I've seen it done on other websites but I have no idea how they do it, and no idea what to type in google to get a good guide to teach me how to do it.
  11. Is that file included in another file or run directly?
  12. Hey guys, I'm not sure where to start with this one so I thought it would be best if I explain what I want to achieve and then hopefully you awesome guys can point me in the right direction for getting it done. I have a table with users. I have another table with ratings and comments for users. What I want to do is pick the top 5 rated users, a random comment, and then display them sequentially one at a time on my website. I have a box on the right hand side of the website in which the top rated user's details would be displayed, along with the random comment. After x number of seconds it would fade to another user. Once it gets back to the first user I would like it to load another random comment using Ajax. How would I go about this?
  13. OK, I could be blind but I didn't see anything in the TOS about not deleting threads. Doesn't matter though, I just didn't want to make clutter.
  14. It's actually just the Ajax not working. The first problem is a coding one, not the tables stopping it form working. How do I get the ajax working again from within the table? EDIT: Damnit, was just a typo. All working now. Can someone please delete this thread?
  15. Not sure if this belongs in this forum or the PHP forum, but as it's the HTML table that breaks it I think it belongs here. I have a form with 2 drop down boxes, one for regions, one for constellations. When the region box is updated it loads the constellation box with all the constellations from that region using Ajax. Unformatted it works perfectly fine, but it's messy so I put it into a table to tidy things up. However 2 things are broken. Firstly, the Ajax code no longer works, it's called correctly (I put an alert into the script to test and that comes up fine) but the constellations selection box doesn't get updated as it should. Secondly, when the page loads it checks the users current location and sets them as the initial $selectedRegion and $selectedConstellation. These are being loaded by the page correctly as they are outputted as a message to the user, but they aren't being used by the table properly as the Region box shows the default option and the Constellation box is empty. The Ajax code in the header is: <script type="text/javascript"> function funcAjax(str) { alert("AJAX script called"); if (str=="") { document.getElementById("ajaxResult").innerHTML="<select name=\"selectedConstellation\"><option value=\"\">Select Region First</option></select>"; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("ajaxResult").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","scripts/constellation.php?r="+str+"&p=i",true); //Call script to update drop down box xmlhttp.send(); } </script> The code in question is: <?php //Display information on where the character is and the location selected for fleets to be displayed echo "<p>Welcome " . $_SESSION['charName'] . ", you are currently in " . $_SESSION['charConstellation'] . ".<br>"; echo "Currently displaying fleets from " . $selectedConstellation . ", " . $selectedRegion . ".</p>"; //Display table with form for updating the location selected for fleets to be displayed echo "<table class=\"selected\">"; echo "<form name=\"updateLocation\" method=\"post\" action=\"indextest2.php\">"; echo "<tr>"; echo "<td><b>Change Region:</b></td>"; echo "<td><select name=\"selectedRegion\" onchange=\"javascript:funcAjax(this.value);\">"; $sqlLoadRegions = "SELECT * FROM regions ORDER BY region"; $queryLoadRegions = mysql_query($sqlLoadRegions); while($rowLoadRegions = mysql_fetch_array($queryLoadRegions)) { //Load all the regions into the drop down menu $region = $rowLoadRegions['region']; $value = $rowLoadRegions['value']; if("$value" == "$selectedRegion") //Test to see if the region being loaded is the current region the user is in echo "<option value=\"$value\" selected=\"selected\">$region</option>"; else echo "<option value=\"$value\">$region</option>"; } echo "</select></td>"; echo "</tr>"; echo "<tr>"; echo "<td><b>Change Constellation:</b></td>"; $table = "constellations" . strtolower($selectedRegion); $sqlLoadConstellations = "SELECT * FROM `$table` ORDER BY constellation"; $queryLoadConstellations = mysql_query($sqlLoadConstellations); echo "<td id=\"ajaxUpdate\"><select name=\"selectedConstellation\">"; //Ajax update area while($rowLoadConstellations = mysql_fetch_array($queryLoadConstellations)) { //Load all the constellations into the drop down menu $constellation = $rowLoadConstellations['constellation']; $value = $rowLoadConstellations['value']; if("$value" == "$selectedConstellation") //Test to see if the constellation being loaded is the current region the user is in echo "<option value=\"$value\" selected=\"selected\">$constellation</option>"; else echo "<option value=\"$value\">$constellation</option>"; } echo "</select></td>"; //End of Ajax update area echo "</tr>"; echo "<tr>"; echo"<td colspan=\"2\"><input name=\"submit\" type=\"submit\" value=\"Display Fleets\"></td>"; echo "</tr>"; echo "</form>"; //End of form to update location selected echo "</table>"; Can someone help me get this working in a table and explain why it works out of a table but not in a table?
  16. OK, we have progress... damn typo lol. It seems that I had fixed it and then broken it again with the Alert typo. The Ajax script is now working as inteded with the code : <select name=\"fleetLocationRegion\" onchange=\"javascript:funcAjax(this.value);\"> Seems all it needed was the javascript: in front of it. Thank you for your help with this rather frustrating problem.
  17. If they're all doing the same thing can't you create 1 function and have the output of that function be variable, with that variable the name of the div id you need updating?
  18. A bit more googling later and my code is now: echo "<form name=\"selectRegion\" action=\"\">"; echo "Fleet Location: <select name=\"fleetLocationRegion\" onchange=\"javascript:funcAjax(this.selectedIndex);\">"; echo "<option value=\"\">Selecte Region</option>"; echo "<option value=\"aridia\">Aridia</option>"; echo "<option value=\"blackrise\">Black Rise</option>"; echo "<option value=\"derelik\">Derelik</option>"; echo "<option value=\"devoid\">Devoid</option>"; echo "<option value=\"domain\">Domain</option>"; echo "<option value=\"essence\">Essence</option>"; echo "<option value=\"genesis\">Genesis</option>"; echo "<option value=\"heimatar\">Heimatar</option>"; echo "<option value=\"kador\">Kador</option>"; echo "<option value=\"khanid\">Khanid</option>"; echo "<option value=\"korazor\">Korazor</option>"; echo "<option value=\"lonetrek\">Lonetrek</option>"; echo "<option value=\"metropolis\">Metropolis</option>"; echo "<option value=\"moldenheath\">Molden Heath</option>"; echo "<option value=\"placid\">Placid</option>"; echo "<option value=\"sinqlaison\">Sinq Laison</option>"; echo "<option value=\"solitude\">Solitude</option>"; echo "<option value=\"tashmurkon\">Tash-Murkon</option>"; echo "<option value=\"thebleaklands\">The Bleak Lands</option>"; echo "<option value=\"thecitadel\">The Citadel</option>"; echo "<option value=\"theforge\">The Forge</option>"; echo "<option value=\"vergevendor\">Verge Vendor</option>"; echo "</select>"; echo "</form>"; echo "<form name=\"createFleet\" method=\"post\" action=\"scripts/fleet.php\">"; echo "<input name=\"fleetSize\" type=\"hidden\" value=\"1\">"; echo "<div id=\"ajaxResult\">"; echo "Constellation: <select name=\"fleetLocationConstellation\">"; echo "<option value=\"\">Select Region First</option>"; echo "</select>"; echo "</div>"; echo "<input name=\"submit\" type=\"submit\" value=\"Create Fleet\">"; echo "</form>"; Still not working...
  19. Constellation.php: <?php /* Load constellations script: This script loads the constellations of a region from the database depending on the region selected by the user. It responds to the AJAX request. */ require("../includes/config.php"); //Check region has been passed to script if(isset($_GET['r'])) $region = "constellations" . $_GET['r']; else die('Error: No constellation passed to script.'); if(!$dbCon) //Connect to the database die('Could not connect to the database: ' . mysql_error()); //Stop script and display error if connecton fails mysql_select_db($dbName, $dbCon); //Select database $sqlLoadConstellations = "SELECT * FROM `$region`"; //Set sql to select constellations $queryLoadConstellations = mysql_query($sqlLoadConstellations); //Set query echo "Constellation: <select name=\"fleetLocationConstellation\">"; while($rowLoadConstellations = mysql_fetch_array($queryLoadConstellations)) { //Load constellations from the table $constellation = strtolower($rowLoadConstellations['constellation']); $constellation = str_replace(" ", "", $constellation); echo "<option value=\"$constellation\">" . $rowLoadConstellations['constellation'] . "</option>"; } echo "</select>"; mysql_close($dbCon); ?> The table just contains 2 columns, key (auto increment primary) and the constellation name. I have 23 different constellation tables, this is one example: key constellation 1 Afinoo 2 Anama 3 Fabai 4 Helab 5 Leseasesh 6 Maal 7 Mareerieh 8 Mayonhen 9 Ombil 10 Selonat 11 Tid
  20. Thank you, I appreciate it. I have no idea why it's not calling the function, nor how to trouble shoot it.
  21. Nope, putting the Ajax function in the head did nothing. The alert still isn't showing so the ajax script still isn't being called for some reason.
  22. Hi guys, I'm new to Ajax and want to use it to dynamically change 1 drop down list depending on the selection of another. Here is my code: <?php echo "<form name=\"createFleet\" method=\"post\" action=\"scripts/fleet.php\">"; echo "<input name=\"fleetSize\" type=\"hidden\" value=\"1\">"; echo "Fleet Location: <select name=\"fleetLocationRegion\" onchange=\"ajax(this.value)\">"; echo "<option value=\"\">Selecte Region</option>"; echo "<option value=\"aridia\">Aridia</option>"; echo "<option value=\"blackrise\">Black Rise</option>"; echo "<option value=\"derelik\">Derelik</option>"; echo "<option value=\"devoid\">Devoid</option>"; echo "<option value=\"domain\">Domain</option>"; echo "<option value=\"essence\">Essence</option>"; echo "<option value=\"genesis\">Genesis</option>"; echo "<option value=\"heimatar\">Heimatar</option>"; echo "<option value=\"kador\">Kador</option>"; echo "<option value=\"khanid\">Khanid</option>"; echo "<option value=\"korazor\">Korazor</option>"; echo "<option value=\"lonetrek\">Lonetrek</option>"; echo "<option value=\"metropolis\">Metropolis</option>"; echo "<option value=\"moldenheath\">Molden Heath</option>"; echo "<option value=\"placid\">Placid</option>"; echo "<option value=\"sinqlaison\">Sinq Laison</option>"; echo "<option value=\"solitude\">Solitude</option>"; echo "<option value=\"tashmurkon\">Tash-Murkon</option>"; echo "<option value=\"thebleaklands\">The Bleak Lands</option>"; echo "<option value=\"thecitadel\">The Citadel</option>"; echo "<option value=\"theforge\">The Forge</option>"; echo "<option value=\"vergevendor\">Verge Vendor</option>"; echo "</select>"; echo "<div id=\"ajaxResult\">"; echo "Constellation: <select name=\"fleetLocationConstellation\">"; echo "<option value=\"\">Select Region First</option>"; echo "</select>"; echo "</div>"; echo "<input name=\"submit\" type=\"submit\" value=\"Create Fleet\">"; echo "</form>"; ?> <script type="text/javascript"> function ajax(str) { if (str=="") { document.getElementById("ajaxResult").innerHTML="Constellation: <select name=\"fleetLocationConstellation\"><option value=\"\">Select Region First</option></select>"; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("ajaxResult").innerHTML=xmlhttp.responseText; } } Alert("Ajax Sent"); xmlhttp.open("GET","constellation.php?r="+str,true); xmlhttp.send(); } </script> For some reason when the first drop down list is changed it's not calling the javascript subroutine. I added the alert to see if the ajax request was being sent and nothing. I copied an example from http://w3schools.com/php/php_ajax_database.asp and as far as I can tell this should be working. Can someone help please?
  23. Vel

    MySQL syntax error

    It's now throwing up another error as well, which I've not seen before. I've included everything in the page. It seems the table name isn't being loaded. But why does it work when a person is in a fleet? Line 57 is $fleetName = $fleetNames[$i]; btw. EDIT: That brings up another question. Why is it trying to search for number 1? There is only 1 fleet, so it should be 0. If I ignore the first row in the array (0) will that work? Nope, that just changes it to undefined offset 0. Is it because I add an extra i++ even when there is no more fleets and it's not hitting that when there is someone in the fleet. I need to change it to $numberOfFleets = $i-1. That was it. Solved. Either $numberOfFleets = $i-1 or use $i < $numberOfFleets instead of <=. It was trying to access a non-existent array.
  24. Hello all. I'm getting a syntax error that I don't understand. When the result is 0 it throws an error, but when the result is 1 it works perfectly fine. Can someone explain why? <?php //Check if character is in a fleet $_SESSION['charIsInFleet'] = FALSE; //Set fleet flag false $sqlLoadFleetNames = "SELECT * FROM `activefleets`"; //Set sql search $queryLoadFleetNames = mysql_query($sqlLoadFleetNames); //Set query $i = 0; while($row = mysql_fetch_array($queryLoadFleetNames)) { $fleetNames[$i] = $row['fleetName']; $i++; } $numberOfFleets = $i; for($i = 0; $i <= $numberOfFleets; $i++) { $fleetName = $fleetNames[$i]; $sqlSearchFleet = "SELECT * FROM `" . $fleetName . "` WHERE `charId` = '" . $charId . "'"; //Set sql search $querySearchFleet = mysql_query($sqlSearchFleet) or die('Error: ' . mysql_error()); $resultSearchFleet = mysql_num_rows($querySearchFleet); if($resultSearchFleet > 0) { $rowSearchFleet = mysql_fetch_array($querySearchFleet); $_SESSION['charIsInFleet'] = TRUE; $_SESSION['charFleetName'] = $fleetName; $_SESSION['charShipHull'] = $rowSearchFleet['shipHull']; $_SESSION['charShipType'] = $rowSearchFleet['shipType']; break; } } When it finds a person in a fleet then it works. When someone is not in an active fleet it throws the error:
  25. Notice you have left of the closing double quote after the } and before the >. That could be the issue. Change echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>"; to echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}\">" . $charName . "</a></td>"; Indeed it was. Thanks a lot .
×
×
  • 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.