Leveecius Posted November 2, 2009 Share Posted November 2, 2009 Hey guys, I'm having an issue with a small script. I want it to show in my game that when you get killed and you try to log in to the game, it will tell you that you're killed and give the posted reason by someone else. I have the you have been killed down, but not the reason. Is my coding right? <style type="text/css"> <!-- .style9 {font-size: 46px} --> </style> <?php mysql_query("SELECT deathreason FROM users WHERE username=$username"); ?> <div align="center"><b><br><br><br><br><br><br><br><br><br> <span class="style9">You have been killed!</span></b></div> <div align="center"><b><br><br><br> <span class="style9">Reason:</span></b></div> <div align="center"><b><br><br><br> <span class="style9"><?php echo"$rows['reason']";?></span></b></div> Here is the Error I get: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/klrbal/public_html/Mafia-test/dead.php on line 16 Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted November 2, 2009 Share Posted November 2, 2009 <span class="style9"><?php echo"$rows['reason']";?></span></b></div> should be <span class="style9"><?php echo $rows['reason']; ?></span> Quote Link to comment Share on other sites More sharing options...
kristofferlc Posted November 2, 2009 Share Posted November 2, 2009 <style type="text/css"> <!-- .style9 {font-size: 46px} --> </style> <?php $query = mysql_query("SELECT deathreason FROM users WHERE username=$username"); $rows = mysql_fetch_assoc($query) ?> <div align="center"><b><br><br><br><br><br><br><br><br><br> <span class="style9">You have been killed!</span></b></div> <div align="center"><b><br><br><br> <span class="style9">Reason:</span></b></div> <div align="center"><b><br><br><br> <span class="style9"><?php echo $rows['reason'];?></span></b></div> That should work, you need to make the rows array. Quote Link to comment Share on other sites More sharing options...
Leveecius Posted November 2, 2009 Author Share Posted November 2, 2009 ok, that worked at least a little bit anyways. I can't get it to echo that row for some reason. It gives the message you have been killed, and it says reason, and it's blank under that.?? Quote Link to comment Share on other sites More sharing options...
UQ13A Posted November 2, 2009 Share Posted November 2, 2009 ok, that worked at least a little bit anyways. I can't get it to echo that row for some reason. It gives the message you have been killed, and it says reason, and it's blank under that.?? Under your mysql_query have you added the bit kristofferlc pointed out $rows = mysql_fetch_assoc($query); Quote Link to comment Share on other sites More sharing options...
Leveecius Posted November 2, 2009 Author Share Posted November 2, 2009 kristoff, I tried your arrays, and got this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/klrbal/public_html/Mafia-test/dead.php on line 8 Quote Link to comment Share on other sites More sharing options...
kristofferlc Posted November 2, 2009 Share Posted November 2, 2009 kristoff, I tried your arrays, and got this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/klrbal/public_html/Mafia-test/dead.php on line 8 Sorry for slow response. Okay, are you sure you've been making a connection to the database before your query? And selected database? Like: $connection = mysql_pconnect($hostname, $username, $password); mysql_select_db($database, $connection); $query = mysql_query("SELECT deathreason FROM users WHERE username=$username", $connection); $rows = mysql_fetch_assoc($query); And make sure to remember the " ; " after each code line, i see i forgot it in my first post at the $rows var. Quote Link to comment Share on other sites More sharing options...
kristofferlc Posted November 2, 2009 Share Posted November 2, 2009 allso, you might want to put some single quotes around your $username array in your query, just for stability with a space or something. Quote Link to comment Share on other sites More sharing options...
kristofferlc Posted November 2, 2009 Share Posted November 2, 2009 I'm very sorry, but i've got to go now. If you have made a connection and all that, this code should work: <style type="text/css"> <!-- .style9 {font-size: 46px} --> </style> <?php $query = mysql_query("SELECT deathreason FROM users WHERE username=$username"); $rows = mysql_fetch_assoc($query); ?> <div align="center"><b><br><br><br><br><br><br><br><br><br> <span class="style9">You have been killed!</span></b></div> <div align="center"><b><br><br><br> <span class="style9">Reason:</span></b></div> <div align="center"><b><br><br><br> <span class="style9"><?php echo $rows['reason'];?></span></b></div> If you haven't made connection, try it. And if it still fails for you, try replacing mysql_fwtch_assoc($query) with mysql_fetch_row($query), and echo $rows[0]; instead. If this still doesn't help, i'll be back in like 9 hours, and will try helping you there. (Unless someone else helped you. ) Good luck, and sorry i had to go. :-/ (Maybe even try echo mysql_result($query); Quote Link to comment Share on other sites More sharing options...
Leveecius Posted November 2, 2009 Author Share Posted November 2, 2009 got this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/klrbal/public_html/Mafia-test/dead.php on line 9 Here is my code: <style type="text/css"> <!-- .style9 {font-size: 46px} --> </style> <?php include "connect.php"; $query = mysql_query("SELECT deathreason FROM users WHERE username=$username"); $rows = mysql_fetch_assoc($query); ?> <div align="center"><b><br><br><br><br><br><br><br><br><br> <span class="style9">You have been killed!</span></b></div> <div align="center"><b><br><br><br> <span class="style9">Reason:</span></b></div> <div align="center"><b><br><br><br> <span class="style9"><?php echo $rows['deathreason'];?></span></b></div> Quote Link to comment Share on other sites More sharing options...
Leveecius Posted November 2, 2009 Author Share Posted November 2, 2009 Got it! It's working now. Here is the code: <style type="text/css"> <!-- .style9 {font-size: 46px} --> </style> <?php include "connect.php"; $query = mysql_query("SELECT deathreason FROM users WHERE username='$username'"); $rows = mysql_fetch_assoc($query); ?> <div align="center"><b><br><br><br><br><br><br><br><br><br> <span class="style9">You have been killed!</span></b></div> <div align="center"><b><br><br><br> <span class="style9">Reason:</span></b></div> <div align="center"><b><br><br><br> <span class="style9"><?php echo $rows['deathreason'];?></span></b></div> Thanks for the help guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.