Any idea why this isn't working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
2DaysAway
Forum Newbie
Posts: 8
Joined: Thu Oct 18, 2007 4:35 pm

Any idea why this isn't working?

Post by 2DaysAway »

I want a message bar to appear if a player has been attacked or sent a message. When I load the script, the page is blank. I think it's my echo's but I've tried several ways and all same result.

Look at it and let me know if you see any code problems or know a better way to write it.

Thanks.

Code: Select all

 
 <?php $get = mysql_query("SELECT round FROM $tab[set] WHERE starts<$time and ends>$time ORDER BY starts ASC;");
while ($game = mysql_fetch_array($get)){
if(fetch("SELECT pimp FROM $tab[pimp] WHERE id='$id' AND rid='$game[round]';")){
$jo3 = "SELECT * from pimps where id='$id' AND rid='$game[round]'";
$jo4 = mysql_query($jo3);
$jo5 = mysql_fetch_array($jo4) or die ("Cannot Recieve Message");
 if($jo5["messages"] >= 1) {
echo = "<table border='0' align='center' cellpadding='0' cellspacing='0'><tr><td>";
echo = "<div class=\"msg\"><div align=\"center\">";
echo = "<a href='inbox.php?rid=$game[round]'>You Have Mail!</a>";
echo = "</div></div>";
echo = "</td></tr></table>";
}
if($jo5["attacks"] >= 1) {
echo = "<table border='0' align='center' cellpadding='0' cellspacing='0'><tr><td>";
echo = "<div class=\"attacked\"><div align=\"center\">";
echo ="<a href='inbox.php?inbox=1&rid=$game[round]'>You've Been Attacked!</a>";
echo = "</div></div>";
echo = "</td></tr></table>";
  }
}
?>
 
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: Any idea why this isn't working?

Post by jimthunderbird »

I guess your sql maybe wrong. Did you try to debug it in phpmyadmin?

Also, try putting {} around the array element in your sql string, for example:

Code: Select all

 
$myarr['id'] = 1;
$sql = "select * from mytable where id = '{$myarr['id']}'";
 
2DaysAway
Forum Newbie
Posts: 8
Joined: Thu Oct 18, 2007 4:35 pm

Re: Any idea why this isn't working?

Post by 2DaysAway »

I'm looking around phpmyadmin and I don't see where to debug scripts. Do you know where to look more specifically, thanks.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Any idea why this isn't working?

Post by Zoxive »

Code: Select all

<?php
$query = "SELECT round FROM `{$tab[set]}` WHERE `starts`<$time and `ends`>$time ORDER BY `starts` ASC";
$get = mysql_query($query);
if (!$get) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
?>
Have you done the basics and throw in error checking for every mysql query?
2DaysAway
Forum Newbie
Posts: 8
Joined: Thu Oct 18, 2007 4:35 pm

Re: Any idea why this isn't working?

Post by 2DaysAway »

ok, I added the query warning and got rid of the equal signs in the echo. I get no warning and still a blank screen. So would that be because of my echos now or do you still think there is a query problem?

Code: Select all

 
 <?php
  $query = "SELECT round FROM `{$tab[set]}` WHERE `round`='$rid'";
 $get = mysql_query($query);
 if (!$get) {
 $message  = 'Invalid query: ' . mysql_error() . "\n";
 $message .= 'Whole query: ' . $query;
 die($message);
 }
while ($game = mysql_fetch_array($get)){
if(fetch("SELECT pimp FROM `{$tab[pimp]}` WHERE `id`='$id' AND `rid`='$game[round]';")){
$jo3 = "SELECT * FROM pimps WHERE `id`='$id' AND `rid`='$game[round]'";
$jo4 = mysql_query($jo3);
$jo5 = mysql_fetch_array($jo4) or die ("Cannot Recieve Message");
 if($jo5["messages"] >= 1) {
echo  "<table border='0' align='center' cellpadding='0' cellspacing='0'><tr><td>";
echo  "<div class=\"msg\"><div align=\"center\">";
echo  "<a href='inbox.php?rid=$game[round]'>You Have Mail!</a>";
echo  "</div></div>";
echo  "</td></tr></table>";
}
if($jo5["attacks"] >= 1) {
echo  "<table border='0' align='center' cellpadding='0' cellspacing='0'><tr><td>";
echo  "<div class=\"attacked\"><div align=\"center\">";
echo "<a href='inbox.php?inbox=1&rid=$game[round]'>You've Been Attacked!</a>";
echo  "</div></div>";
echo  "</td></tr></table>";
 }
  }?>
 
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: Any idea why this isn't working?

Post by jimthunderbird »

2DaysAway wrote:I'm looking around phpmyadmin and I don't see where to debug scripts. Do you know where to look more specifically, thanks.
try printing out your sql, copy it and run it in phpmyadmin see if there's any result back
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Any idea why this isn't working?

Post by Zoxive »

Zoxive wrote:Have you done the basics and throw in error checking for every mysql query?
You are still could be getting a mysql error when you select data from your `pimps` table.

also, put..

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors',true);
At the top of the page.
Post Reply