hi,
Iam viru
can any one help me in creating the addproducts page

Dani AI

Generated

Building on 's request and the hints from , and , here is a compact, practical pattern for an "Add Product" page: a simple schema for categories/products, a safe HTML form, and a PHP handler using PDO prepared statements. Focus is on validation, secure uploads, and keeping category relationships clear.

Suggested schema (categories + products):

CREATE TABLE categories (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL
);

CREATE TABLE products (
  id INT AUTO_INCREMENT PRIMARY KEY,
  category_id INT NOT NULL,
  name VARCHAR(150) NOT NULL,
  description TEXT,
  price DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  stock INT NOT NULL DEFAULT 0,
  image_path VARCHAR(255),
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (category_id) REFERENCES categories(id)
);

Minimal form (note enctype for file uploads and a CSRF token):

<form method="post" action="add_product.php" enctype="multipart/form-data">
  <input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token']); ?>">
  <input name="name" required maxlength="150">
  <textarea name="description"></textarea>
  <input name="price" type="number" step="0.01" required>
  <input name="stock" type="number" required>
  <select name="category_id">...options from categories...</select>
  <input type="file" name="image" accept="image/*">
  <button type="submit">Add Product</button>
</form>

Handler outline (validate, secure-upload, insert using PDO):

<?php
session_start();
// Validate CSRF and inputs (name, numeric price/stock, category exists)
// Handle file: check $_FILES['image']['error'], size, MIME/extension, move_uploaded_file to a non-executable uploads dir
$pdo = new PDO('mysql:host=localhost;dbname=shop;charset=utf8mb4','dbuser','dbpass',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare('INSERT INTO products (category_id,name,description,price,stock,image_path) VALUES (?,?,?,?,?,?)');
$stmt->execute([$category_id,$name,$description,$price,$stock,$image_path]);

Troubleshooting notes: enable PDO exceptions, check php.ini upload_max_filesize and post_max_size, ensure upload directory permissions and that it is outside the webroot or disallows script execution, validate/escape outputs to prevent XSS, and prefer prepared statements over deprecated mysql_* calls. For prepared-statement details see PDO prepared statements.

Recommended Answers

All 6 Replies

Please provide more details.

can you say for which appication you want to develope

All you need to do is have an HTML form posting to a PHP handler, which will update the database. Please provide more details though.

Do you want code or just idea about it.

from my knowledge create categories and subcategories depending upon your products and then store those categories into database.If imistaken your question ignore this.

hi,
i require code
and i think u r very good u reply me early my friend

commented: if they don't reply, they are not good????? +2

you just try to write code for adding products by using mysql insert query and implement the other things you want in your application...
then post us if any errors...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.