/    Sign up×
Community /Pin to ProfileBookmark

Soccer Prediction Page

Hi Guys

Fairly new to Php but have grasped a few things.

I roughly have what i want which is a page that displays data from the mysql database in a form instead of table format.

Im struggling with the updating of the data. I want the users to enter data and the data being entered writing over the data from the previous week?

Any idea’s where im going wrong?

Any help would be appreciated

Thanks

Bazjones

[code=php]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<HEAD>
<TITLE>Premier League Predictor</TITLE>
</head>

<body>

<? include “mysql_connect_prediction.php”; ?>

<?
$db_table = “prediction”;
$query = “SELECT `date`, `match`, `bazza`, `fletcher`, `foxy`, `steve`, `stellios` from `$db_table`” or die (“Could Not Run Query”);
$result = mysql_query($query);
$get_info = mysql_fetch_array($result);

// Get number of rows and columns in PCR database
$num_rows = mysql_num_rows($result);
$num_cols = mysql_num_fields($result);

// Output title fields first
echo ‘<table cellspacing=”0″ cellpadding=”1″ border=”1″>’;
echo ‘<tr bgcolor=#EEFFFF align=left><th>Date</th><th>Match</th><th>Bazza</th><th>Fletcher</th><th>Foxy</th><th>Steve</th><th>Stellios</th></tr><tr>’;

echo ‘<form action=”‘;
echo($PHP_SELF);
echo ‘” method=POST>’;

// Loop through each row printing out values
for ( $i=1; $i <= $num_rows; $i++ )
{
$row = mysql_fetch_row($result);

for ($j=0; $j < $num_cols; $j++ )
{
if ($j==0)
{
echo ‘<td><input type=”TEXT” name=”date” value=”‘;
echo $row[$j];
echo ‘”></td>’;
}
if ($j==1)
{
echo ‘<td><input type=”TEXT” name=”match” value=”‘;
echo $row[$j];
echo ‘”></td>’;
}
if ($j==2)
{
$bazza = array(“Home Win”,
“Away Win”,
“Draw”);

# probably “nicer” to get above list of names from a database table?
echo <<<EOD
<td><select name=”bazza” id=”bazza”>
EOD;
# add each eng as an option:
foreach($bazza as $value)
{
$selected = “”;
if($value == $row[$j])
{
# mark this one as the selected entry:
$selected = ” selected”;
}
echo “<option$selected>$value</option>n”;
}
echo <<<EOD
</select></td>
EOD;
}
if ($j==3)
{
$fletcher = array(“Home Win”,
“Away Win”,
“Draw”);

# probably “nicer” to get above list of names from a database table?
echo <<<EOD
<td><select name=”fletcher” id=”fletcher”>
EOD;
# add each eng as an option:
foreach($fletcher as $value)
{
$selected = “”;
if($value == $row[$j])
{
# mark this one as the selected entry:
$selected = ” selected”;
}
echo “<option$selected>$value</option>n”;
}
echo <<<EOD
</select></td>
EOD;
}
if ($j==4)
{
$foxy = array(“Home Win”,
“Away Win”,
“Draw”);

# probably “nicer” to get above list of names from a database table?
echo <<<EOD
<td><select name=”foxy” id=”foxy”>
EOD;
# add each eng as an option:
foreach($foxy as $value)
{
$selected = “”;
if($value == $row[$j])
{
# mark this one as the selected entry:
$selected = ” selected”;
}
echo “<option$selected>$value</option>n”;
}
echo <<<EOD
</select></td>
EOD;
}
if ($j==5)
{
$steve = array(“Home Win”,
“Away Win”,
“Draw”);

# probably “nicer” to get above list of names from a database table?
echo <<<EOD
<td><select name=”steve” id=”steve”>
EOD;
# add each eng as an option:
foreach($steve as $value)
{
$selected = “”;
if($value == $row[$j])
{
# mark this one as the selected entry:
$selected = ” selected”;
}
echo “<option$selected>$value</option>n”;
}
echo <<<EOD
</select></td>
EOD;
}
if ($j==6)
{
$stellios = array(“Home Win”,
“Away Win”,
“Draw”);

# probably “nicer” to get above list of names from a database table?
echo <<<EOD
<td><select name=”stellios” id=”stellios”>
EOD;
# add each eng as an option:
foreach($stellios as $value)
{
$selected = “”;
if($value == $row[$j])
{
# mark this one as the selected entry:
$selected = ” selected”;
}
echo “<option$selected>$value</option>n”;
}
echo <<<EOD
</select></td></tr>
EOD;
}
}
}
?>

<tr><td><input name=”update_date” type=SUBMIT class=”button” id=”update_date” value=”Update”></td>
<td><input name=”update_match” type=SUBMIT class=”button” id=”update_match” value=”Update”></td>
<td><input name=”update_bazza” type=SUBMIT class=”button” id=”update_bazza” value=”Update”></td>
<td><input name=”update_fletcher” type=SUBMIT class=”button” id=”update_fletcher” value=”Update”></td>
<td><input name=”update_foxy” type=SUBMIT class=”button” id=”update_foxy” value=”Update”></td>
<td><input name=”update_steve” type=SUBMIT class=”button” id=”update_steve” value=”Update”></td>
<td><input name=”update_stellios” type=SUBMIT class=”button” id=”update_stellios” value=”Update”></td>
</tr>
</table>
<br>
</form>

<?
if($_POST[‘update_date’])
{
$query = “UPDATE `prediction` SET `date` = ‘”. $_POST[“date”] .”‘”;
$result = mysql_query($query);
};
?>
<?
if($_POST[‘update_match’])
{
$query = “UPDATE `prediction` SET `match` = ‘”. $_POST[“match”] .”‘”;
$result = mysql_query($query);
};
?>
<?
if($_POST[‘update_bazza’])
{
$query = “UPDATE `prediction` SET `bazza` = ‘”. $_POST[“bazza”] .”‘”;
$result = mysql_query($query);
};
?>
<?
if($_POST[‘update_fletcher’])
{
$query = “UPDATE `prediction` SET `fletcher` = ‘”. $_POST[“fletcher”] .”‘”;
$result = mysql_query($query);
};
?>
<?
if($_POST[‘update_foxy’])
{
$query = “UPDATE `prediction` SET `foxy` = ‘”. $_POST[“foxy”] .”‘”;
$result = mysql_query($query);
};
?>
<?
if($_POST[‘update_steve’])
{
$query = “UPDATE `prediction` SET `steve` = ‘”. $_POST[“steve”] .”‘”;
$result = mysql_query($query);
};
?>
<?
if($_POST[‘update_stellios’])
{
$query = “UPDATE `prediction` SET `stellios` = ‘”. $_POST[“stellios”] .”‘”;
$result = mysql_query($query);
};
?>
</body>
<div><hr></div>
<div class=”footer”>Last Updated: <!– #BeginDate format:acAm1a –>Mon, August 22, 2005 10:12 AM<!– #EndDate –></div>
</html>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @bazjones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...