Jump to content

[SOLVED] Echo help!


Leveecius

Recommended Posts

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

Link to comment
Share on other sites

<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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.