我是 php 的新手,我必须设计一个名为 fixtures.php 的页面。在此页面中,使用 if/else 语句在同一页面上进行列出、编辑和删除。
这是我目前拥有的 fixtures.php 页面。任何帮助表示赞赏。
<?php
include ('connect.php');
$user_name="root";
$password="";
$database="team_management_db";
$server="127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if($db_found){
echo "Database found";
}
$fixture_id=$_GET['fixture_id'];
$submit=$_POST['update'];
$update=$_GET['fixture_id'];
$delete=$_GET['fixture_id'];
$SQL = "SELECT * FROM fixtures";
$result = mysql_query($SQL);
echo "<table border='1'><tr bgcolor='#cccccc'><td>Opponents</td><td>Date</td><td>Venue</td><td>Action</td>";
while($row = mysql_fetch_assoc($result)) {
$fixture_id=$row['fixture_id'];
$opponents=$row['opponents'];
$date=$row['date'];
$venue=$row['venue'];
echo "<tr><td>$opponents</td><td>$date</td><td>$venue</td><td><a href=fixtures.php?action=update&fixture_id=. $update .>Edit</a>
</td><td><a href=fixtures.php?action=delete&fixture_id= . $delete . >Delete</a></td></tr>";
}
echo "</table>";
if($update)
{
?>
<form action=$_PHP_SELF method=POST>
<table border='1'><tr bgcolor='#cccccc'><td>Opponents</td><td>Date</td><td>Venue</td></tr>
<tr><td><input type='hidden' name='fixture_id' />
<input type='text' name='opponents' />
<input type='text' name='date' />
<input type='text' name='venue' />
<input type='submit' name='update' value='update' />
</td>
</tr>
</form>
<?php
}
?>
<?php
if($delete)
{
echo "Are you sure you want to delete $fixture?<a href=fixtures.php?delete=absolutely&fixture_id=$fixture_id>Yes</a>
<a href=fictures.php>No</a>";
if($delete=='absolutely')
{
$sql = "DELETE FROM fixtures WHERE fixture_id = $fixture_id";
}
}
elseif($submit=='update')
{
$fixture_id=$_POST['fixture_id'];
$opponents=$_POST['opponents'];
$date=$_POST['date'];
$venue=$_POST['venue'];
$sql = "UPDATE FROM fixtures SET opponents =$opponents, date =$date, venue =$venue
WHERE fixture_id = $fixture_id";
mysql_select_db('team_management_db');
$retval = mysql_query($sql, $db_handle);
if(!$retval)
{
die('Could not update data: ' .mysql_erroe());
}
echo "Updated data successfully\n";
mysql_close($db_handle);
}
else
{
echo "<table border='1'><tr bgcolor='#cccccc'><td>Opponents</td><td>Date</td><td>Venue</td></tr>";
while($row = mysql_fetch_assoc($result)) {
$fixture_id=$row['fixture_id'];
$opponents=$row['opponents'];
$date=$row['date'];
$venue=$row['venue'];
echo "<tr><td>$opponents</td><td>$date</td><td>$venue</td></tr>";
}
echo "</table>";
}
?>
</body>
</html>