Page 1 of 1

Help in a php script :)

Posted: Mon Mar 01, 2004 3:19 pm
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]

Posted: Mon Mar 01, 2004 3:22 pm
by Illusionist
uhm... its not

Posted: Mon Mar 01, 2004 3:27 pm
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 :(

Posted: Mon Mar 01, 2004 3:28 pm
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 ?

Re: Help in a php script :)

Posted: Mon Mar 01, 2004 3:31 pm
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>";
?>

Posted: Mon Mar 01, 2004 3:33 pm
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

Posted: Mon Mar 01, 2004 3:36 pm
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

Posted: Mon Mar 01, 2004 3:38 pm
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

Posted: Mon Mar 01, 2004 3:38 pm
by Flamie
Patrik, I tried your script, and it didnt change anything :(