Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: coopster & jatar k

Help with If Statement. Not sure what to do

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

5+ Year Member



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>

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



This should be as follows:

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

notice the quotes

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

5+ Year Member



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.
2:54 am on Sep 12, 2007 (gmt 0)

5+ Year Member




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

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month