Here you go:
PHP Code:
<?php
if(isset($_POST['save']))
{
$title = $_POST['title'];
$content = $_POST['content'];
if(!get_magic_quotes_gpc())
{
$title = addslashes($title);
$content = addslashes($content);
}
// image upload
$date = date('l dS F, Y');
// $_FILES['userfile']['name'] is the name of the pic sent. This name needs to go into the database so then the database can call it.
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$file_realname = trim($_FILES['userfile']['name']);
$uploaddir = "uploaded/";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $file_realname)){
}
else{
print "<strong>$file_realname</strong> did not upload!";
}
// this is so when it displays the file size to the user it is in KB
$size = round(($_FILES['userfile']['size'] / 1024), 1);
// image upload end
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO news (title, content, category, picname, picsize, picdate) VALUES ('$title', '$content', '$category', '$file_realname', '$size', '$date')";
mysql_query($query) or die('Error ,query failed');
$query1 = "SELECT id, parentCat FROM category ORDER BY id";
$result = mysql_query($query1) or die('Error : ' . mysql_error());
include 'library/closedb.php';
echo "Artikal '$title' dodat u bazu";
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
<tr>
<td width="100">Title</td>
<td><input name="title" type="text" class="box" id="title"></td>
</tr>
<tr>
<td width="100">Category</td>
<td><select name="category" class="box" id="category">
<option value="">--- Izaberi postojeću ---</option>
<?
while($row = mysql_fetch_array($result)) {
print_r("<option value=\"%s\">%s</option>", $row['parentCat'], $row['parentCat']);
} ?>
</select>
</td>
</tr>
<tr>
<td width="100">Content</td>
<td><textarea name="content" cols="60" rows="10" class="box" id="content"></textarea></td>
</tr>
<tr>
<td width="100">Upload Image</td>
<td> <input type="hidden" name="MAX_FILE_SIZE" value="5120000">
<input name="userfile" type="file" size="40" class="box"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="save" type="submit" class="box" value="Save Article">
</td>
</tr>
</table>
</form>
Bookmarks