Cơ sở dữ liệu APACHE, PHP, MYSQL - 28

?>” method=”post”>

<?php

if (!empty($_GET[‘error’]))

{

echo “<div align=”center” “ . “style=”color:#000000;background-color:#FF0000;” . “font-weight:bold”>” . nl2br(urldecode($_GET[‘error’])) . “</div><br />”;

}

?>

<table border=”0” width=”750” cellspacing=”1” cellpadding=”3” bgcolor=”#353535” align=”center”>

<tr>

<td bgcolor=”#FFFFFF” width=”30%”>Movie Name</td>

Có thể bạn quan tâm!

Xem toàn bộ 258 trang tài liệu này.

<td bgcolor=”#FFFFFF” width=”70%”>

<input type=”text” name=”movie_name” value=”<?php echo $movie_name?>”>

Cơ sở dữ liệu APACHE, PHP, MYSQL - 28

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF”>Movie Type</td>

<td bgcolor=”#FFFFFF”>

<select id=”game” name=”movie_type” style=”width:150px”>

<option value=”” selected>Select a type...</option>

<?php

$sql = “SELECT movietype_id, movietype_label “ . “FROM movietype ORDER BY movietype_label”;

$result = mysql_query($sql)

or die(“<font color=”#FF0000”>Query Error</font>” . mysql_error()); while ($row = mysql_fetch_array($result))

{

if ($row[‘movietype_id’] == $movie_type)

{


}

else

{


}

$selected = “ selected”;


$selected = “”;

echo ‘<option value=”’ . $row[‘movietype_id’] . ‘“‘ . $selected . ‘>’ . $row[‘movietype_label’] . “</option>rn”;

}

?>

</select>

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF”>Movie Year</td>

<td bgcolor=”#FFFFFF”>

<select name=”movie_year”>

<option value=”” selected>Select a year...</option>

<?php

for ($year=date(“Y”); $year >= 1970 ;$year--)

{

if ($year == $movie_year)

{


}

else

{


}

$selected = “ selected”;


$selected = “”;

?>

<option value=”<?php echo $year; ?>”

<?php echo $selected; ?>><?php echo $year; ?></option>

<?php

}

?>

</select>

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF”>Lead Actor</td>

<td bgcolor=”#FFFFFF”>

<select name=”movie_leadactor”>

<option value=”” selected>Select an actor...</option>

<?php

foreach ($people as $people_id => $people_fullname)

{

if ($people_id == $movie_leadactor)

{


}

else

{


}

?>

$selected = “ selected”;


$selected = “”;

<option value=”<?php echo $people_id; ?>”

<?php echo $selected; ?>><?php echo $people_fullname;

?></option>

<?php

}

?>

</selected>

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF”>Director</td>

<td bgcolor=”#FFFFFF”>

<select name=”movie_director”>

<option value=”” selected>Select a director...</option>

<?php

foreach ($people as $people_id => $people_fullname)

{

if ($people_id == $movie_director)

{


}

else

{


}

?>

$selected = “ selected”;


$selected = “”;

<option value=”<?php echo $people_id; ?>”

<?php echo $selected; ?>><?php echo $people_fullname;

?></option>

<?php

}

?>

</select>

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF” width=”30%”> Movie release date (dd-mm-yyyy)

</td>

<td bgcolor=”#FFFFFF” width=”70%”>

<input type=”text” name=”movie_release”

value=”<?php echo date(“d-m-Y”, $movie_release); ?>”>

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF” width=”30%”> Movie rating (0 to 10)

</td>

<td bgcolor=”#FFFFFF” width=”70%”>

<input type=”text” name=”movie_rating” value=”<?php echo $movie_rating; ?>”>

</td>

</tr>

<tr>

<td bgcolor=”#FFFFFF” colspan=”” align=”center”>

<input type=”submit” name=”submit” value=”<?php echo $_GET[‘action’]; ?>”>

</td>

</tr>

</table>

</form>

</body>

</html>


2.Bây giờ file commit.php và thay đổi như sau:

<?php

// COMMIT ADD AND EDITS

$error = ‘’;

$link = mysql_connect(“localhost”, “root”, “”) or die(“Could not connect: “ . mysql_error()); mysql_select_db(‘moviesite’, $link)

or die ( mysql_error()); switch ($_GET[‘action’])

{

case “edit”:

switch ($_GET[‘type’])

{

case “people”:

$sql = “UPDATE people SET “ .

“people_fullname = ‘“ . $_POST[‘people_fullname’] . “‘ WHERE people_id = ‘“ . $_GET[‘id’] . “‘“;

break;

case “movie”:

$movie_rating = trim($_POST[‘movie_rating’]); if (!is_numeric($movie_rating))

{


}

else

{

$error .= “Please+enter+a+numeric+rating+%21%0D%0A”;


if ($movie_rating < 0 || $movie_rating > 10)

{

$error .= “Please+enter+a+rating+” . “between+0+and+10%21%0D%0A”;

}

}

if (!ereg(“([0-9]{2})-([0-9]{2})-([0-9]{4})”,

$_POST[‘movie_release’] ,

$reldatepart))

{


}

else

{

$error .= “Please+enter+a+date+” . “with+the+dd-mm-yyyy+format%21%0D%0A”;

$movie_release = @mktime(0, 0, 0, $reldatepart[‘2’],

$reldatepart[‘1’],

$reldatepart[‘3’]);

if ($movie_release == ‘-1’)

{

$error .= “Please+enter+a+real+date+” . “with+the+dd-mm-yyyy+format%21%0D%0A”;

}

}

$movie_name = trim($_POST[‘movie_name’]); if (empty($movie_name))

{

$error .= “Please+enter+a+movie+name%21%0D%0A”;

}

if (empty($_POST[‘movie_type’]))

{

$error .= “Please+select+a+movie+type%21%0D%0A”;

}

if (empty($_POST[‘movie_year’]))

{

$error .= “Please+select+a+movie+year%21%0D%0A”;

}

if (empty($error) )

{


}

else

{


}

break;

}

break;

$sql = “UPDATE movie SET “ .

“movie_name = ‘“ . $_POST[‘movie_name’] . “‘,” .

“movie_year = ‘“ . $_POST[‘movie_year’] . “‘,” . “movie_release = ‘$movie_release’,” . “movie_type = ‘“ . $_POST[‘movie_type’] . “‘,” .

“movie_leadactor = ‘“ . $_POST[‘movie_leadactor’] . “‘,” . “movie_director = ‘“ . $_POST[‘movie_director’] . “‘,” . “movie_rating = ‘$movie_rating’” .

“WHERE movie_id = ‘“ . $_GET[‘id’] . “‘“;


header(“location:movie.php?action=edit&error=” .

$error . “&id=” . $_GET[‘id’]);

case “add”:

switch ($_GET[‘type’])

{

case “people”:

$sql = “INSERT INTO people (people_fullname) “ . “VALUES (‘“ . $_POST[‘people_fullname’] . “‘)”; break;

case “movie”:

$movie_rating = trim($_POST[‘movie_rating’]); if (!is_numeric($movie_rating))

{

$error .= “Please+enter+a+numeric+rating+%21%0D%0A”;

}

..... Xem trang tiếp theo?
⇦ Trang trước - Trang tiếp theo ⇨

Ngày đăng: 06/01/2024