Help with code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Patsman77
Forum Newbie
Posts: 18
Joined: Thu Jun 04, 2009 10:09 am

Help with code

Post 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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Help with code

Post by Jade »

Where's the code for checkpick($sql->Player, $Player)? That's what would be re-selecting the player they entered last.
Patsman77
Forum Newbie
Posts: 18
Joined: Thu Jun 04, 2009 10:09 am

Re: Help with code

Post by Patsman77 »

You are correct. I found the error and have fixed. Thanks for your response.
Post Reply