Problem je sljedeci zelim da dodam vijesti u kategorije, dole ispod je kod u kojem je greska koju ne mogu da nadjem, ako
neko zeli da mi pomogne bio bi mu puno zahvalan.
Citat:CREATE TABLE IF NOT EXISTS `kateg` (
`katID` int(11) NOT NULL auto_increment,
`ime` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`katID`),
KEY `rubrika` (`ime`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=0 ;
Citat:CREATE TABLE IF NOT EXISTS `news` (
`id` int(11) NOT NULL auto_increment,
`naslov` varchar(255) NOT NULL,
`vijesti` text NOT NULL,
`kateg` varchar(60) NOT NULL,
`novosti` text NOT NULL,
`timestamp` bigint(20) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
ADMINISTRACIJA_VIJESTI.PHP
Citat:
<?php
$link = mysql_connect('localhost', 'root', '')
or die('Greska: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
?>
<?php
//-----------------------------------------------------
// Provjera 1 : prepravjanje ili pisanje nove vijesti ?
//-----------------------------------------------------
if (isset($_POST['naslov']) AND isset($_POST['vijesti']) AND isset($_POST['novosti']))
{
$naslov = addslashes($_POST['naslov']);
$vijesti = addslashes($_POST['vijesti']);
$novosti = addslashes($_POST['novosti']);
if ($_POST['id_news'] == 0)
{
mysql_query("INSERT INTO news VALUES('', '" . $naslov . "', '" . $vijesti . "', '" . $_POST['kateg'] . "', '" . $novosti . "', '" . time() . "')");
}
else
{
$_POST['id_news'] = addslashes($_POST['id_news']);
mysql_query("UPDATE news SET kateg='" . $_POST['kateg'] . "', naslov='" . $naslov . "', vijesti='" . $vijesti . "', novosti='" . $novosti . "' WHERE id='" . $_POST['id_news'] . "'");
}
}
//--------------------------------------------------------
// Provjera 2 : brisanje vijesti ?
//--------------------------------------------------------
if (isset($_GET['izbrisite_vijest']))
{
$_GET['izbrisite_vijest'] = addslashes($_GET['izbrisite_vijest']);
mysql_query('DELETE FROM news WHERE id=\'' . $_GET['izbrisite_vijest'] . '\'');
}
?>
<?php
$retour = mysql_query('SELECT * FROM news ORDER BY id DESC');
while ($prikazi = mysql_fetch_array($retour))
{
?>
<div id="narandjasti-meni"><ul>
<li><?php echo '<a href="dodajte_vijesti.php?prepravite_vijest=' . $prikazi['id'] . '">'; ?>PREPRAVI</a></li>
<li><?php echo '<a href="administracija_vijesti.php?izbrisite_vijest=' . $prikazi['id'] . '">'; ?>IZBRISI</a></li>
<li><a href="#"><?php echo stripslashes($prikazi['naslov']); ?></a></li>
<li><a href="#"><?php echo date('d/m/Y', $prikazi['timestamp']); ?></a></li>
</ul>
</div>
<?php
}
?>
DODAJTE_VIJESTI.PHP
Citat:
<?php
$link = mysql_connect('localhost', 'root', '')
or die('Greska: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
?>
<?php
if (isset($_GET['prepravite_vijest']))
{
$_GET['prepravite_vijest'] = mysql_real_escape_string(htmlspecialchars($_GET['prepravite_vijest']));
$retour = mysql_query('SELECT * FROM news WHERE id=\'' . $_GET['prepravite_vijest'] . '\'');
$prikazi = mysql_fetch_array($retour);
$naslov = stripslashes($prikazi['naslov']);
$vijesti = stripslashes($prikazi['vijesti']);
$novosti = stripslashes($prikazi['novosti']);
$id_news = $prikazi['id'];
}
else
{
$naslov = '';
$vijesti = '';
$novosti = '';
$id_news = 0;
}
?>
<form action="administracija_vijesti.php" method="post">
<p>Naslov : <input type="text" size="30" name="naslov" value="<?php echo $naslov; ?>" /></p>
<p>
Vijesti 1 :<br />
<textarea name="vijesti" cols="50" rows="10">
<?php echo $vijesti; ?>
</textarea><br />
<p>
Vijesti 2 :<br />
<textarea name="novosti" cols="50" rows="10">
<?php echo $novosti; ?>
</textarea><br />
<input type="hidden" name="id_news" value="<?php echo $id_news; ?>" />
<tr>
<td>Rubrika:</td>
<td align="left" class="unos"><label for="label"></label>
<select name="ime" id="label">
<?php
$sql = 'SELECT * FROM `kateg`;';
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_assoc($result)):
echo '<option value="'.$row['kadID'].'">'.$row['ime'].'</option>';
endwhile;
?>
</select>
</td>
</tr>
<input type="submit" value="Dodajte Vijest" />
</p>
</form>
KATEGORIJA.PHP
Citat:
<?php
$link = mysql_connect('localhost', 'root', '')
or die('Greska: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
?>
<?php
$greska = 0;
$kategorija = $HTTP_POST_VARS[ime];
if (empty($kategorija)) {
$greska++;
}
if ($greska == 0) {
$sql = 'INSERT INTO kateg (ime) VALUES( "'.$kategorija.'")';
if (mysql_query($sql))
{
echo '<div align="center">
Kategorija dodata!!!
</div>
';
} else
{
echo "Greska prilikom upisa u bazu:" . mysql_error();
}
}
else
{
echo '
<div align="center">
Upisite ime kategorije!<br>
</div>
';
}
?>
DODAJ_KATEGORIJU.PHP
Citat:
<?php
$link = mysql_connect('localhost', 'root', '')
or die('Greska: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
?>
<h2>Kategorija</h2>
<form action="kategorija.php" method="post" name="form1" id="form1">
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<th scope="col">Dodaj novu kategoriju:</th>
<th scope="col"><input name="ime" type="text" id="ime3" size="50" /></th>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit3" value="Dodaj" /></td>
</tr>
</table>
<hr />
</form>
<?php
$potvrda = "'Sigurno zelis izbrisat?'";
$order = $HTTP_GET_VARS[order];
$query = 'SELECT * FROM kateg '.$order.';';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_assoc($result)):
echo'
<tr>
<td><a href="kategorija_obrisi.php?id='.$row['katID'].'" onclick="javascript:return confirm('.$potvrda.')"></td>
<td>'.$row['katID'].'</td>
<td><a href="kategorija_izmjena.php?id='.$row['katID'].'">'.$row['ime'].'</a> </td>
<td>';
$sql1 = 'SELECT COUNT( * ) AS `in` FROM `news` WHERE kateg="'.$row['kateg'].'";';
$query1 = mysql_query($sql1) or die('Query failed: ' . mysql_error());
$row1 = mysql_fetch_array($query1);
echo $row1['in'];
echo'</td>
</tr>
';
endwhile;
?>
</table>
KATEGORIJA_IZMJENA.PHP
Citat:
<?php
$link = mysql_connect('localhost', 'root', '')
or die('Greska: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
?>
<?php
$id = $HTTP_GET_VARS[id];
$akcija = $HTTP_GET_VARS[akcija];
if ($akcija == "snimi") {
$id = $HTTP_GET_VARS[id];
$ime = $HTTP_POST_VARS[ime];
$sql = '
UPDATE `kateg` SET
`ime` = "'.$ime.'"
WHERE `katID` = "'.$id.'" LIMIT 1;
';
if (mysql_query($sql))
{
echo '<div align="center">Kategorija uspjesno izmjenjena!!!</div>';
} else
{
echo "GRESKA:" . mysql_error();
}
}
if (empty($akcija)) {
$query = 'SELECT * FROM `kateg` WHERE `katID` = "'.$id.'" LIMIT 1;';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_assoc($result)):
echo '
<h2>Kategorije</h2>
<form action="kategorija_izmjena.php?id='.$id.'&akcija=snimi" method="post" name="form1" id="form1">
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<th scope="col">Dodaj novu kategoriju:</th>
<th scope="col"><input name="ime" type="text" id="ime3" size="50" value="'.$row['ime'].'"/></th>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit3" value="Izmjeni" /></td>
</tr>
</table>
</form>
';
endwhile;
mysql_free_result($result);
}
?>
KATEGORIJA_OBRISI.PHP
Citat:
<?php
$link = mysql_connect('localhost', 'root', '')
or die('Greska: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
?>
<?php
$id = $HTTP_GET_VARS[id];
$query = 'DELETE FROM `kateg` WHERE `katID` = "'.$id.'" LIMIT 1;';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo '<div align="center">Kategorija obrisana!!!</div>';
?>
|