Help in a php script :)

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
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Help in a php script :)

Post by Flamie »

Code: Select all

<?php
<tr>
<td align='center' class='row1'>Winning Clan:</td>
<td class='row1' align='left'>
<select name='winningclan' size='1' style='width:140px;'>
<option selected>-Winning clan\/";

$query = mysql_query( "SELECT * FROM `clan_reg` ORDER BY `tag`" );
for($i=1;$i<=mysql_num_rows($query);$i++)
{
$thisrow = mysql_fetch_array($query);
print "
<option value='$thisrow[tag]'>$thisrow[tag]</option>";
}



print"

</td></tr>


?>


in the page itself the correct options appear in the select menu, but all the values are 0 !, you can see it @ http://www.wormaholic.com/temp/report,php, the page works fine, the report works fine too, exept the values of the "winning clan" and the "losing clan" are 0 and not the tag itself.
PS, the script for the losing clan is the same as the winning.
Does anyone know why its always 0 ?
Thanks in advance,
Flamie [/php_man]
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

uhm... its not
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

I looked thru it over 100 times and still cant see why its 0, but whenever some1 submits, teh values in the DB are 0 for the wining clan and the losing clan :(
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

When you view the html source of the link above the values look ok (to me anyway), so maybe the problems in your DB code?
Maybe post the relevant chunk of code that handles the db insertion/form posting ?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Re: Help in a php script :)

Post by patrikG »

Try

Code: Select all

<?php
<tr>
<td align='center' class='row1'>Winning Clan:</td>
<td class='row1' align='left'>
<select name='winningclan' size='1' style='width:140px;'>
<option selected>-Winning clan\/";

$query = mysql_query( "SELECT * FROM `clan_reg` ORDER BY `tag`" );
for($i=1;$i<=mysql_num_rows($query);$i++)
{
$thisrow = mysql_fetch_array($query);
print "<option value='".$thisrow['tag']."'>".$thisrow['tag']."</option>";
}

print"</td></tr>";
?>
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

Well in the select bar, all the correct "tags" appear, so I dont see why it doesnt get the tag as a value.
Anyways here's the script where I insert the values in the DB:

Code: Select all

<?php
$winningclan = addslashes( $_POST['winningclan'] );
	$losingclan = addslashes( $_POST['losingclan'] );
	$gametype = addslashes( $_POST['gametype'] );
	$win1 = addslashes( $_POST['win1'] );
	$win2 = addslashes( $_POST['win2'] );
	$los1 = addslashes( $_POST['los1'] );
	$los2 = addslashes( $_POST['los2'] );

	mysql_query( "INSERT INTO games_rep ( clanid1, clanid, type, win_play1, win_play2, los_play1, los_play2 ) VALUES ( '$winningclan', '$losingclan', '$gametype', '$win1', '$win2', '$los1', '$los2' )" );
?>

And its not a connection problem or anything cuz all teh values are entered correctly in teh DB exept for "winningclan"and "losingclan"

Flamie
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What are the column types of clanid1 and clanid? If they are INT's then it might explain the problem as the form values are not int's :o
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

In associative arrays, you need quotes around the keys, e.g.
$array["mykey"]="myValue";

Why is $foo[bar] wrong? http://uk.php.net/manual/en/language.types.array.php
Last edited by patrikG on Mon Mar 01, 2004 3:38 pm, edited 1 time in total.
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

Patrik, I tried your script, and it didnt change anything :(
Post Reply