Zdravim snazim sa urobit ulohu z knihy PHP6, MySQL, Apache z kapitoly c. 6.
Mam tento kod:
admin.php:
Kód:
<?php
$db = mysql_connect('localhost', 'mino', 'krisko') or die('Chyba pripojenia!');
mysql_select_db('moviesite', $db) or die(mysql_error($db));
?>
<html>
<head>
<title>Databaza filmoveho klubu</title>
<style = type="text/css">
th { background-color: #999; }
.odd_row { background-color: #EEE; }
.even_row { background-color: #FFF; }
</style>
</head>
<body>
<table style="width:100%;">
<tr>
<th colspan ="2">Filmy <a href="movie.php?action=pridat">[PRIDAT]</a></th>
</tr>
<?php
$query = 'SELECT * FROM movie';
$result = mysql_query($query, $db) or die(mysql_error($db));
$odd = true;
while($row = mysql_fetch_assoc($result)) {
echo ($odd == true)? '<tr class="odd_row">': '<tr class="even_row">';
$odd = !$odd;
echo '<td style="width:75%;">';
echo $row['movie_name'];
echo '</td><td>';
echo ' <a href="movie.php?action=upravit&id='. $row['movie_id'] .'"> [UPRAVIT]</a>';
echo ' <a href="delete.php?type=movie&id='. $row['movie_id'] .'"> [ODSTRANIT]</a>';
echo '</td></tr>';
}
?>
<tr>
<th colspan="2">Osoby <a href="people.php?action=pridat"> [PRIDAT]</a></th>
</tr>
<?php
$query = 'SELECT * FROM people';
$result = mysql_query($query, $db) or die(mysql_error($db));
$odd = true;
while ($row = mysql_fetch_assoc($result)) {
echo ($odd = true)? '<tr class="odd_row">': '<tr class="even_row">';
$odd = !$odd;
echo '<td style="width: 25%;">';
echo $row['people_fullname'];
echo '</td><td>';
echo ' <a href="people.php?action=upravit&id='. $row['people_id'] .'"> [UPRAVIT]</a>';
echo ' <a href="delete.php?type=people&id='. $row['people_id'] .'"> [ODSTRANIT]</a>';
echo '</td></tr>';
}
?>
</table>
</body>
</html>
people.php
Kód:
<?php
$db = mysql_connect('localhost', 'mino', 'krisko') or die('Chyba pripojenia!');
mysql_select_db('moviesite', $db) or die(mysql_error($db));
if($_GET['action'] == 'upravit') {
$query = 'SELECT people_id, people_fullname, people_isactor, people_isdirector
FROM people WHERE people_id = '. $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
extract(mysql_fetch_assoc($result));
} else {
$people_fullname = '';
$people_isactor = 0;
$people_isdirector = 0;
}
?>
<html>
<head>
<title>Zmena dat osoby </title>
</head>
<body>
<form action="commit.php?action=<?php echo $_GET['action']; ?>&type=people" method="post">
<table>
<tr>
<td>Meno osoby</td>
<td><input type="text" name="people_name" value="<?php echo $people_fullname; ?>"/></td>
</tr><tr>
<td>Zamestanie</td>
<td><input type="radio" name="typ" value="1" checked="checked" />Herec<br />
<input type="radio" name="typ" value="0" />Reziser<br />
</td>
</tr>
<tr>
<td>
<?php
if ($_GET['action'] == 'upravit') {
echo '<input type="hidden" value="'. $_GET['id'] .'" name="cislo" />';
}
?>
<input type="submit" name="submit" value="Odoslat" />
</td>
</tr>
</table>
</form>
</body>
</html>
commit.php
Kód:
<?php
$db = mysql_connect('localhost', 'mino', 'krisko') or die ('Nemohu se pøipojit. Zkontrolujte prosím pøipojení k serveru.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));
?>
<html>
<head>
<title>Potvrdenie transakcie</title>
</head>
<body>
<?php
switch ($_GET['action']) {
case 'pridat':
switch ($_GET['type']) {
case 'movie':
$query = 'INSERT INTO
movie
(movie_name, movie_year, movie_type, movie_leadactor,
movie_director)
VALUES
("' . $_POST['movie_name'] . '",
' . $_POST['movie_year'] . ',
' . $_POST['movie_type'] . ',
' . $_POST['movie_leadactor'] . ',
' . $_POST['movie_director'] . ')';
break;
case 'people':
if ($_GET['typ'] == '1') {
$query = 'INSERT INTO people (people_fullname, people_isdirector, people_isactor)
VALUES
("'. $_POST['people_name']. '", 0, 1)';
}
else
{
$query = 'INSERT INTO people (people_fullname, people_isdirector, people_isactor)
VALUES
("'. $_POST['people_name']. '", 1, 0)';
}
break;
}
break;
case 'upravit':
switch ($_GET['type']) {
case 'movie':
$query = 'UPDATE movie SET
movie_name = "' . $_POST['movie_name'] . '",
movie_year = ' . $_POST['movie_year'] . ',
movie_type = ' . $_POST['movie_type'] . ',
movie_leadactor = ' . $_POST['movie_leadactor'] . ',
movie_director = ' . $_POST['movie_director'] . '
WHERE
movie_id = ' . $_POST['movie_id'];
break;
case 'people':
if ($_POST['typ'] == '1') {
$query = 'UPDATE people SET
people_fullname = "'. $_POST['people_name']. '",
people_isdirector = 0,
people_isactor = 1
WHERE people_id = '. $_POST['cislo'];
}
else
{
$query = 'UPDATE people SET
people_fullname = "'. $_POST['people_name']. '",
people_isdirector = 1,
people_isactor = 0
WHERE people_id = '. $_POST['cislo'];
}
break;
}
break;
}
if (isset($query)) {
$result = mysql_query($query, $db) or die(mysql_error($db));
}
?>
<p>Hotovo!</p>
</body>
</html>
Ked sa dostanem na stranku commit.php tak mi vypise tento problem:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/www/html/commit.php on line 64
Uz nad tym sedim dost dlho a stale som nenasiel chybu...
Nevie niekto kde je chyba?? S upravovanim tabulky movie som nemal problem, vsetko fungovalo tak ako ma.
Za kazdu pomoc vopred dakujem.