homepage Welcome to WebmasterWorld Guest from 50.19.199.154
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Help with If Statement. Not sure what to do
Darkstars31




msg:3448026
 12:19 am on Sep 12, 2007 (gmt 0)

Below is my code. My current problem is that my IF statement always returns false, so it wont display my teams in the table, however if i view the team to see whos on the team (The players on the team), that will show up because the IF statement returned false and used the second $result. So what do i need to put in that if statement to view all the teams in 1 table, basically how do i make it return True when i want to view the table with all the teams in it.
-----------------Code Below-------------
list($game, $type)= explode('', $_POST[game]);
if($type == game){$result = mysql_query( "SELECT TeamName,Owner,Wins,Loses FROM $dbname WHERE game_name = '$_POST[game]'")or die("SELECT Error: ".mysql_error());
} else {
$result = mysql_query ( "SELECT user_id FROM $dbnametwo WHERE Teamname = '$_POST[game]'")or die("SELECT Error: ".mysql_error());
}
$num_rows = mysql_num_rows($result);
print "There are $num_rows Teams/Players.<P>";
print "<table width=600 border=1>\n<tr><td>Team Names/Players</td><td>Owner</td><td>W</td><td>L</td></tr> </table>";
print "<table width=600 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
<form method="POST">
<Select name="game">
<option></option>
<?php
while (list($game_selection) = mysql_fetch_row($find)) {
$display = "<option value=\"$game_selection\">$game_selection</option>";
echo $display;
while (list($team_selection) = mysql_fetch_row($find2)) {
$display2 = "<option value=\"$team_selection\">*$team_selection</option>";
echo $display2; }
}
?>

</select>

 

eelixduppy




msg:3448028
 12:28 am on Sep 12, 2007 (gmt 0)

This should be as follows:

if($type == "game"){$result = mysql_query....

notice the quotes

Darkstars31




msg:3448032
 12:32 am on Sep 12, 2007 (gmt 0)

Adding the "" quotes around game doesn't make it work. Any other suggestions? Ive tried alot of things im not sure i fully understand the List() or the explode() functions, even though ive studied them on w3schools.

Steerpike




msg:3448118
 2:54 am on Sep 12, 2007 (gmt 0)


You appear to have a few issues, and all of them are combining to result in a series of broken steps. I fear you're trying to debug an issue that's too far down a broken chain.

I'll note a few of the issues I spotted so you can try and break down what you're doing into smaller, more easily debugged parts.

list($game, $type)= explode('', $_POST[game]);
should be:
list($game, $type)= explode('', $_POST["game"]);

if($type == game)
should be:
if($type == $game)

$result = mysql_query( "SELECT TeamName,Owner,Wins,Loses FROM $dbname WHERE game_name = '$_POST[game]'")or die("SELECT Error: ".mysql_error());
should be:
$result = mysql_query( "SELECT TeamName,Owner,Wins,Loses FROM $dbname WHERE game_name = '$game'")or die("SELECT Error: ".mysql_error());
IMPORTANT:
You are using potentially 'tainted' data in your sql statement (ie, you're 'assuming' that the information coming in through $_POST is clean and hasn't been altered in any way). This is a major security risk in your application and you'll need to review this when you have the other parts working.

mysql_query ( "SELECT user_id FROM $dbnametwo WHERE Teamname = '$_POST[game]'")or die("SELECT Error: ".mysql_error());
should be:
mysql_query ( "SELECT user_id FROM $dbnametwo WHERE Teamname = '$team'")or die("SELECT Error: ".mysql_error());
(also, again you're assuming 'cleanliness' of potentially unsafe data in this call).

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved