Jump to content

kingb00zer

Members
  • Posts

    128
  • Joined

  • Last visited

Everything posted by kingb00zer

  1. Yeah I have a connection file I included into the script. From what I can gather this script is giving me 0 rows that match the crtiera even though there are 3 personal messages sent to my account (visible when i observe the database) which is telling me the query on line 94 is somehow incorrect. I have not yet tried to use AND in sql or multiple WHERE clauses in the same statement until now so you think that might be the problem?
  2. ok after attempting to write this script I reallise it wasnt as straight forward as I thought before. Ok so far I ahve this code echo "<table class='centrepage' width='600px' align='center'>";echo "<tr><td class='seven' align='center' colspan='8'> Inbox - Sent - Alliance - Message Board - Attacks In - Attacks Out <br /></td></tr>"; $count= 0 ;$query = mysql_query("SELECT * FROM messages WHERE to='" . $_SESSION['username'] . "' AND WHERE category='personal' ");$rowcount= mysql_num_rows($query); // THIS IS ROW 95while ($count <= $rowcount){while($row = mysql_fetch_array($query)) { // THIS IS ROW 99$from= $row['from'];$message= $row['message'];$date= $row['date'];}echo "<tr bgcolor='#006622'><td colspan='8' class='seven'><b>From: $from</b> $date</td></tr>";echo "<tr><td colspan='8' class='seven'>$message</td></tr>";$count++;}echo "</table>"; EDIT: (forgot to add the result) Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in F:\Ashs stuff\Web Dev Stuff\School ######\xampp\htdocs\dealer game\messages.php on line 95 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\Ashs stuff\Web Dev Stuff\School ######\xampp\htdocs\dealer game\messages.php on line 99 So basically in this table I want it to generate 2 rows on each loop, the top one to say who the message is form and at what time and date it arrived, then in the next row display the message. The table in the database this information is being retrieved from may contain many diferent messages for the user so it is important that the messages not only match the users name in the "to" field but the category fields needs to match to the word "personal" also. Any idea what to do here?
  3. OMG lol I didnt even need to post this problem. I forgot that i had read about sql operpators for and and or and assumed that I remembered them from reading php tutorials (hense this question in the php forum.) now that I reallise "AND" can be used I now understand how to tackle my problem. Thank you
  4. The where clause is what i use to select all from messages where the field "to" is equal to $_SESSION['username']But i cant work out how to refine that search so that on the inbox page i only get messages from where category= "personal" and where to= 'my username'.
  5. kingb00zer

    Hard To Explain

    hey, I am trying to add messaging into a site I am building and so far I have a table in the database with the fields date, to, from, message, and category. What I am having trouble with is figuring out how to select everything where to is equal to $_SESSION['username'] but also only where category is equal to personal. what should I do?
  6. hmm I didnt think of using include. When another php file is included that simply means that php file is run when that line of code is read right? (I use it for my connection but dont fully understand it)Also I am happy to rely on javascript, just dont fully understand it either yet.EDIT: Thank you I got it to work and learned more about include
  7. Hi I am trying to process a form which has 5 diferent submit options. Basically what I have is 1 text field where I enter a username and then I choose from 1 of 5 attack options. The problem is that with a basic html and php combo of code I cant assign each of the 5 php files to each of the submit buttons. I do reallise that I could put all 5 actions into the same file and run a switch however I already have over 800lines of code on just one and i hate scrolling through large ammounts of to find one line (dont we all?) After googling how to fix this issue I found something about using the javascript onclick thing (havnt really learned JS yet) this seems to be the kind of approach I want to take but dont know how to embed it into my code or weather I need to put any <script='javascript'> type of tags in my head. echo "<form method='post'><table class='target' width='150'>";echo "<tr><td align='left' colspan='1' class='one'>Target:</td><td align='left' colspan='1'> <input type='text' name='target' class='shortcuts' size='10' /></td></tr>";echo "</table>";echo "<table class='carjack' width='150'>";echo "<tr><td align='center' colspan='1' class='seven'>Carjacking</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Thugs: $thugs </td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='carjack.php';' /> </td></tr>";echo "</table>";echo "<table class='other' width='150'>";echo "<tr><td align='center' colspan='1' class='seven'>Other Minor Attack</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> to go</td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Here!' onclick='form.action='other.php';' /> </td></tr>";echo "</table>";echo "<table class='raid' width='150px'>";echo "<tr><td align='center' colspan='2' class='seven'>House Invasion</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Thugs: </td><td align='left' colspan='1' class='one'> $thugs </td></tr>";echo "<tr><td align='center' colspan='1' class='one'> AK47's: </td><td align='left' colspan='1' class='one'> $ak47a</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Pistols: </td><td align='left' colspan='1' class='one'> $pistola</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> </td><td align='left' colspan='1' class='one'> <br /></td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='houseinvasion.php';' /> </td></tr>";echo "</table>";echo "<table class='driveby' width='150px'>";echo "<tr><td align='center' colspan='2' class='seven'>Driveby Shooting</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Thugs: </td><td align='left' colspan='1' class='one'> $thugs </td></tr>";echo "<tr><td align='center' colspan='1' class='one'> AK47's: </td><td align='left' colspan='1' class='one'> $ak47a</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Pistols: </td><td align='left' colspan='1' class='one'> $pistola</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Escalades: </td><td align='left' colspan='1' class='one'> $escalade</td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='driveby.php';' /> </td></tr>";echo "</table>";echo "<table class='turfwar' width='150px'>";echo "<tr><td align='center' colspan='2' class='seven'>Turf War</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Send: </td><td align='left' colspan='1'> <input type='text' name='amount' class='shortcuts' size='10' /></td></tr>";echo "<tr><td align='center' colspan='1' class='one'>Of:</td><td align='left' colspan='1'> <select class='shortcuts' name='drug'><option value='weed'>Weed</option><option value='xtc'>Ecstacy</option><option value='heroin' selected='selected'>Heroin</option> <option value='specialk'>Special K</option> <option value='acid'>Acid</option> <option value='coke'>Coke</option> </select> </td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Price: $</td><td align='left' colspan='1'> <input type='text' name='price' class='shortcuts' size='10' /></td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='turfwar.php';' /> </td></tr>";echo "</table> </form> ";
  8. Thank you, these pages conatin some very interesting information, some things I could see myself using in the future.
  9. Thanks guys, I had a feeling that I had done this once before (at school last year,) a simple round($variable, 2) did the trick. It was the ' , 2 ' that I forgot how to do.
  10. kingb00zer

    number format

    Hey I cant seem to think how to cut off most of the numbers after a decimal point. I want to make 0.0270721925134 look like 0.02 im sure its something simple too. I use the number format funtion sometimes but Im not sure how to get it to do that.
  11. That worked well, Thanks for the help.
  12. Thank you, Ill see how I go with this.
  13. yeah, the plan is to match it to $rank during iterations. but I cant think of a way to link each iteration to the users in the order of networth to get the variable to match it.
  14. ok the $rank variable was supposed ot be the one which increases each iteration of the loop, however need a variable of a similar kind that I can match each iteration to, so that I can display each user in order of networth. What I cant figure out is how to link these iterations to the accounts in the right order.When using loops for other actions i simply matched the id numbers users get when they sign up with the variable that increases on iterations, this is not as easy to do when they need to be listed in a certain order.
  15. my bad I was in a hurry and only cut out the last part of the code forgetting that $rank and $rowcount was declared earlier, full code below. <?phpsession_start();include('connection.php');// get player total count$query= "SELECT * FROM playerstats";$qry= mysql_query($query);$rowcount= mysql_num_rows($qry);$rank= 1;echo "<html>";echo "<head><link rel='stylesheet' type='text/css' href='gamestyles.css' /> </head>";echo "<title> Game.</title>";echo "<body>";echo "<table class='mainpage' align='center'>";echo "<tr><td class='stats'>Rank</td><td class='stats'>Player</td><td class='stats'>Thugs</td><td class='stats'>Dealers</td><td class='stats'>Drugs</td><td class='stats'>Networth</td> </tr>";$rank2=mysql_query("SELECT username, dealers, thugs, drugs, networth FROM playerstats "); //get first player while ($rank <= $rowcount){ $rank1=mysql_query("SELECT username, dealers, thugs, drugs, networth FROM playerstats ORDER BY networth ASC "); while($row=mysql_fetch_array($rank1)) { $username= $row['username']; $dealers= $row['dealers']; $thugs= $row['thugs']; $drugs= $row['drugs']; $drugs= number_format($drugs); $networth= $row['networth']; $networth= number_format($networth); } echo "<tr><td class='stats'>$rank</td><td class='stats'>$username</td><td class='stats'>$dealers</td><td class='stats'>$thugs</td><td class='stats'>$drugs</td><td class='stats'>$networth</td> </tr>"; $rank++;} echo "</table>";?>
  16. Hi I am currently working on a part of my site which displays all of the users in a rankings page. What I want to achieve is a page that lists the users from largest to lowest based on a number in each players row in a table in my database, that number being "networth". So I have done a lot of work with while loops running thrugh all of the users until I get a count variable to match the total number of users whilst matching the count variable to the players id number in the database. But what im having trouble with is getting the order displayed from highest networth to lowest networth, I cant seem to find how to match each repitition of the loop to individual users based on what their "networth" is. When using ORDER BY Does it give everything in that query a number based on its order in the list? If so what do I write to call it on so I can macth it to a count variable and display everyone in order instead of just one person several times over as I get with the code below. echo "<table class='mainpage' align='center'>";echo "<tr><td class='stats'>Rank</td><td class='stats'>Player</td><td class='stats'>Thugs</td><td class='stats'>Dealers</td><td class='stats'>Drugs</td><td class='stats'>Networth</td> </tr>";$rank2=mysql_query("SELECT username, dealers, thugs, drugs, networth FROM playerstats "); //get first player while ($rank <= $rowcount){ $rank1=mysql_query("SELECT username, dealers, thugs, drugs, networth FROM playerstats ORDER BY networth ASC "); while($row=mysql_fetch_array($rank1)) { $username= $row['username']; $dealers= $row['dealers']; $thugs= $row['thugs']; $drugs= $row['drugs']; $drugs= number_format($drugs); $networth= $row['networth']; $networth= number_format($networth); } echo "<tr><td class='stats'>$rank</td><td class='stats'>$username</td><td class='stats'>$dealers</td><td class='stats'>$thugs</td><td class='stats'>$drugs</td><td class='stats'>$networth</td> </tr>"; $rank++;} echo "</table>";
  17. I checked the link and it still didnt register to me, maybe I need to spend a day off form work looking into this a ittle bit more as mostly do my coding after work when im tired and sligthly distracted.
  18. Not sure I understand the whole parametre thing. I thought setting a function was as simple as naming it and then putting the code within that function as what the function is supposed to do. I also thought that changing it into switch would make it easier to read. (im just too used to if else lol)
  19. when you say fucntion dothis($var), I dont understand what variable I am supposed to put into the parenthisis. do I just make one up? this is one fo the functions I am tryng to createfunction getprice() { if ($selling == 1) { $drugprice1= mysql_query("SELECT value FROM heroin"); // find price of that drug while($row=mysql_fetch_array($drugprice1)) { $drugprice= $row['value']; } } else if ($selling == 2) { $drugprice1= mysql_query("SELECT value FROM weed"); // find price of that drug while($row=mysql_fetch_array($drugprice1)) { $drugprice= $row['value']; } } else if ($selling == 3) { $drugprice1= mysql_query("SELECT value FROM xtc"); // find price of that drug while($row=mysql_fetch_array($drugprice1)) { $drugprice= $row['value']; } } else if ($selling == 4) { $drugprice1= mysql_query("SELECT value FROM coke"); // find price of that drug while($row=mysql_fetch_array($drugprice1)) { $drugprice= $row['value']; } } else if ($selling == 5) { $drugprice1= mysql_query("SELECT value FROM specialk"); // find price of that drug while($row=mysql_fetch_array($drugprice1)) { $drugprice= $row['value']; } } else if ($selling == 6) { $drugprice1= mysql_query("SELECT value FROM acid"); // find price of that drug while($row=mysql_fetch_array($drugprice1)) { $drugprice= $row['value']; } } } when I run the script it says "Parse error: syntax error, unexpected ';', expecting '{' in /home/druglord/public_html/selloff.php on line 28" which is the function getprice() line
  20. hey I have recently written a pretty big script and have come to a point where if I can do what IM asking about I may ahve to re write. I have a lot of if statements in thsi script which is starting to get pretty complex and basically I ahve declared a variable at say for example line 10 and then an if statement where in some cases it may change the variable on line 10s value but it needs to run the code above it again. is there a way I can put in a revert back to line 11 type function or something to go abck up?
  21. Im making a turn based browser game, in the username field i want only aplha numeric. in some of the in game fields i only want numeric. and from what I read about sql injection if I can strip other symbols from someones input it can stop people from hacking into and editing my databse.
  22. Nevermind I worked it all out, i forgot that I put it in comments to check if i messed up chance of using old set up but both are fine now. I think I might be close but what have i done wrong here? i entered the name test*&^%/ing to see if it enters testing into the db and it didnt remove any of it. // strip invalid charactors from input fields$username_strip= $_POST['username'];$username= preg_replace("/[^a-z,A-Z,0-9\s]/", "", $username_strip);
  23. hey Im just wondering what the best way to go about protecting forms from not only sql injection but especially in the username fields stripping anything that is not alphanumeric.
  24. thank you synook that worked a treat
×
×
  • Create New...