Hi dear friends. I have an annoying error in php while uploading file in a form. Please help. It is most appreciated. Thanks. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Hi dear friends. I have an annoying error in php while uploading file in a form. Please help. It is most appreciated. Thanks.

This is the error: UERY FAILED You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '4', 'published')' at line 1 ?php if(isset($_POST['create_post'])) { $post_title = $_POST['post_title']; $post_category_id = $_POST['post_category_id']; $post_author = $_POST['post_author']; $post_status = $_POST['post_status']; $post_image = $_FILES['image']['name']; $post_image_temp = $_FILES['image']['tmp_name']; $post_tags = $_POST['post_tags']; $post_content = $_POST['post_content']; $post_date = date('d-m-y'); $post_comment_count = 4; move_uploaded_file($post_image_temp, "../images/$post_image"); $query = "INSERT INTO posts(post_category_id, post_title, post_author, post_date, post_image, post_content, post_tags, post_comment_count, post_status) "; $query .= " VALUES({$post_category_id}, '{$post_title}', '{$post_author}', now(), '{$post_image}', '{$post_content}', '{$post_tags}, '{$post_comment_count}', '{$post_status}') ";

10th Jul 2019, 7:02 PM
ali elham
ali elham - avatar
4 Answers
+ 8
The message tells that there's a problem with your SQL command, I suggest you to do a cross check validation between table field type and their respective insert data in your SQL query. Make sure string and date/time values are quoted (no quotes for numeric types), this is most common as we tend to forget field type as we go.
10th Jul 2019, 8:10 PM
Ipang
+ 6
You're very welcome my friend, yes, it's a common thing, something simple causes big problem, don't feel so bad, it happens to everyone, we're just humans : )
11th Jul 2019, 3:38 PM
Ipang
+ 4
Ipang - Thank you so much my friend. My mistake was forgetting a single closing quote. I canot believe how I have forgotten that and how a single quote wasted my three days. Thank you once again.
11th Jul 2019, 2:30 PM
ali elham
ali elham - avatar
+ 3
You are right.
11th Jul 2019, 3:46 PM
ali elham
ali elham - avatar