Jump to content

what's wrong with this code?


BaLtAzAr
 Share

Recommended Posts

Can someone tell me what's wrong with this code.In a nice add anything you do not want to add, cat_id.Can someone tell me where is the mistake here

<?phpinclude_once('podesavanja.php');session_start();function kategorije($id = null){$categories = array();$query = mysql_query("SELECT `id`, `ime` FROM `cat`");while($row = mysql_fetch_assoc($query)){$categories = $row;}}if (isset($_POST['naslov']) && isset($_POST['tekst']) && isset($_POST['cat'])){$naslov = $_POST['naslov'];$cat = (int) $ime;$tekst = $_POST['tekst'];$date =  date ("Y-m-d H:i:s");$naslov = strip_tags($naslov,"<a><abbr><acronym><address><applet><area><b><base><basefont><bdo><big><blockquote><br><button><caption><center><cite><col><colgroup><dd><del><dfn><dir><div><dl><dt><em><fieldset><font><form><h1><h2><h3><h4><h5><h6><hr><i><img><input><ins><isindex><kbd><label><legend><li><link><map><menu><object><ol><optgroup><option><p><param><pre><q><s><samp><select><small><span><strike><strong><style><sub><sup><table><tbody><td><textarea><tfoot><th><title><tr><tt><u><ul><var>");$tekst = strip_tags($tekst,"<a><abbr><acronym><address><applet><area><b><base><basefont><bdo><big><blockquote><br><button><caption><center><cite><col><colgroup><dd><del><dfn><dir><div><dl><dt><em><fieldset><font><form><h1><h2><h3><h4><h5><h6><hr><i><img><input><ins><isindex><kbd><label><legend><li><link><map><menu><object><ol><optgroup><option><p><param><pre><q><s><samp><select><small><span><strike><strong><style><sub><sup><table><tbody><td><textarea><tfoot><th><title><tr><tt><u><ul><var>");if(empty($naslov)){$error = "Molim vas unesite naslov!!!";}if(strlen($naslov) > 255){$error = "Naslov nesme sadrzati vise od 255 slova!!!";}if(empty($tekst)){$error = "Molim vas unesite tekst!!!";}if(empty($error)){$q = mysql_query("INSERT INTO `".$db_user."`.`blog` (`id`, `naslov`, `blog`, `addedby`, `Date`, `cat_id`) VALUES (NULL, '".$naslov."', '".$tekst."', '".$_SESSION['username']."', '".$date."', '".$cat."');");die ("uspesno dodat artikal: ".$naslov." Vratite se na admin-cp <a href=\"admin.php\">Admin cp </a><br /> ");}}if($_SESSION['username'])echo "Dobrodosli ovde dodajete artikle vasem blogu ";elsedie ("Morate biti ulogovani dabiste videli ovo stranicu  <form action='login.php' method='post'><input type='submit' value='Login' /></form>");?><html><head><link rel="stylesheet" type="text/css" href="style/style.css" /></head><body><form action="addnew.php" method="post"><?phpif(! empty($error)){echo "<ul><li>".$error."</li></ul>";}?>Naslov:<input type="text" name="naslov"/><br /><br /><br /><label for="tekst">Tekst:</label></br><textarea name="tekst" id="data" style="width:500px; height: 300px;"></textarea><br /><select name="cat"><?phpforeach(kategorije() as $category){?><option value="<?php echo $category['id']; ?>"><?php echo $category['name']; ?></option><?php}?></select></br><input type="submit" name="posalji" value="posalji" id="sub"/></form><form action="logout.php" method="post"><input type="submit" name="logout" value="logout" id="sub"/></form><a href="admin.php">Admin cp </a><br /></body></html>

Link to comment
Share on other sites

You did not mention what is not working as expected or if any error is showing. you should have mention those so that we can help you better.

while($row = mysql_fetch_assoc($query)){$categories[]= $row;}return $categories;

the "[ ]" square bracets append $row to array $categories with a incremental index each time it iterate in loop. without itit it will just assign the $row and will omit the previous data. you have to return the value from the function to get the value.

foreach(kategorije() as $category)
here the function is not returning anything now. Edited by birbal
Link to comment
Share on other sites

reference:http://au.php.net/manual/en/language.types.array.phphttp://au.php.net/manual/en/functions.returning-values.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...