Page 1 of 1

Help with code

Posted: Sun Jun 05, 2011 8:47 am
by Patsman77
Hello All,

I have a code I am struggling and hoping someone can show me the error in my ways, This is from a form that posts the results to a database. Everything works except one thing. When I go back to the form, the focus is not the selection of what is in the database. Here is the code:

Code: Select all

<?
$con3= mysql_connect("localhost","xxxxxxxx","xxxxxxx");
mysql_select_db("swammisp_football", $con3);
$sql2="select * from signups WHERE Name='$_SESSION[user]' AND Fantasy='Yes'";
//echo "$sql2<br>";

$infantasy=mysql_query($sql2) or die (mysql_error());
mysql_select_db("swammisp_football", $con3);
$sql="select qb from Fantasy WHERE User='$_SESSION[user]' AND Week=$week";
$result=mysql_query($sql);
if (mysql_num_rows($infantasy) == 0){
	echo "<option value=\"OUT\">Not in pool</option>";
}

else{
$sql3="select qb from Fantasy WHERE user='$_SESSION[user]' AND Week=$week";
$result2 = mysql_query($sql3);
if (mysql_num_rows($result2) == 0){
	$pick = "XXX";
	echo "<option value=\"BAD\" selected>PICK</option>";
}
else {
	$sql=mysql_fetch_object($result2);
	$team = $sql->qb;
}
$sql="select Player from QB";

$result=mysql_query($sql);
while ($sql = mysql_fetch_object($result))
{
//	echo $sql->vid . " (against " . $sql->hid . ")<BR>";
	$qbout[$sql->Player] = "<option value=\"$sql->Player\"" . checkpick($sql->Player, $Player) . ">$sql->Player</option>";
}

sort($qbout);
foreach ($qbout as $team){
	echo $team;
}
//mysql_free_result($result);
}
?>
So basically, when I bring the form back up, it brings up the list of players, which it should incase the user wants to change the player, but it does not focus to the player that the user has already chosen.

Thanks for any help.

Patsman77

Re: Help with code

Posted: Tue Jun 07, 2011 9:36 am
by Jade
Where's the code for checkpick($sql->Player, $Player)? That's what would be re-selecting the player they entered last.

Re: Help with code

Posted: Tue Jun 07, 2011 1:30 pm
by Patsman77
You are correct. I found the error and have fixed. Thanks for your response.