私は 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>