PHP Ecom Part 7 : How to insert / add category with image in database in PHP MySQL | Image Upload

preview_player
Показать описание
Insert data with image in database in PHP MySQL.
In this video, you will learn how to insert / add category with image in database in PHP MySQL.

If the video helps you, hit the like button and subscribe to the channel. If you have any doubts or suggestions, drop them in the comments below and i will answer them.
Thanks for watching

Рекомендации по теме
Комментарии
Автор

Incase you are having errors, i fixed it here, it should work...



<?php

session_start(); // Start the session to use session variables
// Include the database connection file
// Include additional functions

// Check if the add category button is clicked
// Check if the form was submitted
{
// Get and sanitize user input
$name = mysqli_real_escape_string($con, $_POST['name']);
$slug = mysqli_real_escape_string($con, $_POST['slug']);
$description = mysqli_real_escape_string($con, $_POST['description']);
$meta_title = mysqli_real_escape_string($con, $_POST['meta_title']);
$meta_description = mysqli_real_escape_string($con, $_POST['meta_description']);
$meta_keywords = mysqli_real_escape_string($con, $_POST['meta_keywords']);
$status = isset($_POST['status']) ? '1' : '0';
$popular = isset($_POST['popular']) ? '1' : '0';

// Handle file upload
$image = $_FILES['image']['name'];
$path = "../uploads";
$image_ext = pathinfo($image, PATHINFO_EXTENSION);
$filename = time().'.'.$image_ext;

// SQL query to insert the new category into the database
$cate_query = "INSERT INTO categories
(name, slug, description, meta_title, meta_description, meta_keywords, status, popular, image)
VALUES ('$name', '$slug', '$description', '$meta_title', '$meta_description', '$meta_keywords', '$status', '$popular', '$filename')";

// Execute the query
$cate_query_run = mysqli_query($con, $cate_query);

// Check if the query execution was successful
if($cate_query_run)
{
// Move the uploaded file to the specified directory
move_uploaded_file($_FILES['image']['tmp_name'], $path.'/'.$filename);

// Redirect to add-category.php with a success message
redirect("add-category.php", "Category Added Successfully");
}
else
{
// Redirect to add-category.php with an error message if something goes wrong
redirect("add-category.php", "Something went wrong");
}
}
else
{
// Redirect to add-category.php with an error message if the form was not submitted
redirect("add-category.php", "Invalid Access");
}

?>

zetsu_pdf
Автор

Thanks Uche Onuh I have the same problem and finally solved from your comments.Thanks a lot

bodrulhuda
Автор

The solution to the problem of file not uploading to the appropriate folder is to run the command 'chmod 777 in terminal if on Linux, u can update paths if in a different Operating system

vinnnduri
Автор

I have a problem when adding the description textboxes. When adding them, it doesn't let the rest of the code work, and instead the code just displays itself in the description textbox. I've realized this only happens when adding the textarea. And so, I am unsure how to fix this.

Angkuva
Автор

Sir isme data sent nahi hoo Raha hai MySQL me error bhi nahi hai par data bhi show nahi ho Raha hai

smart_parte_
Автор

sir the image does not move to the uploads folder

heinrichsanchez
Автор

I noticed after creating this page that the admin page auth process starts failing and the admin panel can be accessed by typing into the url box with a message saying the redirect was coming from the sidebar. I solved this by removing the include of the middleware file from the index and add-cat page and including it in the header and since both page had the header included, they had the middleware included.

ucheonuh
Автор

if you use macbook but the image does not move to the uploads folder, you turn on the termial chmod -Rf 777 uploads then post the image will be in the uploads folder

hunginh
Автор

why it wont save in my uploads folder?

hmczsqk
Автор

my code is correct but it always error and it isn't sending anything to the database. can you help me?

hyakkimarusempaii
Автор

my data is not getting stored in database. help me out

SARIKAGAUTAM-ie
Автор

i have problem 3 days now, '$cate_query' isn' sending anythiong to database even tho its included in code.php

totomoro
Автор

Hello sharma, I have a problem uploading image to my database, the warning message was : Undefined array key “ image ” in path name on line 173.

Pls how do I solve this issue ?
Thank you.

adamsaleh
Автор

My image not moving to uploads folder I have been trying to fix it for a month now can you help me out

ryangrayson
Автор

how to display username in admin panal after logging into the admin panel page

satishp
Автор

? '1':'0';
I don't understand this here. pls explain for me

khatranthe
welcome to shbcf.ru