I am building a basic CMS. Today I wanted to add the option to upload a thumbnail image. I searched the internet and found a tutorial I could use. Now, after posting, the image uploads correctly and is displayed as it is supposed to be. All perfect.
The problem is now that my other form values don't get posted anymore.. Previously it worked fine, but after adding the option to upload thumbnails, no values get posted to the database except the image filename.
Anyone knows what's wrong with my code?
<form method="POST" enctype="multipart/form-data" name="form">
<select name="category">
<option value="option 1">option 1</option>
</select>
<input type="text"name="topic">
<textarea name="article"></textarea>
<select name="author">
<option>option 1</option>
</select>
<input type="file" name="thumbnail">
<button type="submit" name="post">Post article</button>
</form>
<?php
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
};
$file_name=$_FILES["thumbnail"]["name"];
$temp_name=$_FILES["thumbnail"]["tmp_name"];
$imgtype=$_FILES["thumbnail"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "../magazine/thumbnails/".$imagename;
if(isset($_POST['post']) && move_uploaded_file($temp_name, $target_path)){
$username=mysqli_real_escape_string(db_conx,$_POST['author']);
$topic=mysqli_real_escape_string(db_conx,$_POST['topic']);
$article=mysqli_real_escape_string(db_conx,$_POST['article']);
$category=mysqli_real_escape_string(db_conx,$_POST['category']);
$result=mysqli_query($db_conx,"INSERT INTO articles (`username`,`topic`,`article`,`category`,`thumbnail`) VALUES('$username','$topic','$article','$category','$imagename')");
}
?>
Typo. change this:
to this:
Another problem I see is your variable
db_conx. you are missing the dollar sign$, which is incorrect syntax, unless you are referring to a constant. Change it to$db_conx.