..im new in PHP and and I want to know how to create html form that sends file(images) to phpmyadmin(database) consider that you have to choose the database first from the dropdown list of database.. then display it's table after choosen it.. please help..

here must be the sql flow.. from html form...

<select>
  <option value="DB1">DATABASE 1</option>
  <option value="DB2">DATABASE 2</option>
  <option value="DB3">DATABASE 3</option>
  <option value="DB4" selected>DATABASE 4</option>//selected
</select>

 ==next it will display after you choose one of database==

<select>
  <option value="table_1">table 1</option>
  <option value="table_2">table 2</option>
  <option value="table_3">table 3</option>
  <option value="table_4" selected>table 4</option>// selected
</select>


<submit>

this suppose to be insert to databse 4 table 4..

Dani AI

Generated

For : a practical, safe workflow is to (1) present a controlled list of databases, (2) fetch tables for the chosen database via AJAX, and (3) on submit validate the chosen DB/table, process the uploaded file server-side, then store metadata (or the blob) in the selected table. phpMyAdmin is only an admin UI — the PHP endpoints must validate input and enforce limits. asked what exists so far; the snippets below fill the missing pieces and show the minimal server checks needed.

Client: when the DB select changes request the tables and populate the table select.

/* assumes <select id="db"> and <select id="table"> exist */
document.getElementById('db').addEventListener('change', function(){
  fetch('get_tables.php?db=' + encodeURIComponent(this.value))
    .then(r => r.json())
    .then(tables => {
      const sel = document.getElementById('table');
      sel.innerHTML = '';
      tables.forEach(t => {
        const o = document.createElement('option');
        o.value = t;
        o.textContent = t;
        sel.appendChild(o);
      });
    });
});

Server: example get_tables.php (use PDO; config.php should create $pdo). Validate names before querying.

<?php
require 'config.php'; // creates $pdo
$db = $_GET['db'] ?? '';
if (!preg_match('/^[A-Za-z0-9_]+$/', $db)) { http_response_code(400); echo '[]'; exit; }
$stmt = $pdo->prepare('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :db');
$stmt->execute([':db' => $db]);
echo json_encode($stmt->fetchAll(PDO::FETCH_COLUMN));

Upload handler: validate DB/table against the lists, validate the uploaded file, move to a safe folder, then insert metadata. Do not inject the table name — only use it after verifying it exists in the fetched list.

<?php
require 'config.php';
$db = $_POST['db'] ?? ''; $table = $_POST['table'] ?? '';
if (!preg_match('/^[A-Za-z0-9_]+$/',$db) || !preg_match('/^[A-Za-z0-9_]+$/',$table)) exit('Invalid');
/* verify $db and $table are allowed (compare with INFORMATION_SCHEMA results) */
if ($_FILES['image']['error']===UPLOAD_ERR_OK){
  $tmp = $_FILES['image']['tmp_name'];
  $mime = mime_content_type($tmp);
  $allowed = ['image/jpeg','image/png','image/gif'];
  if (!in_array($mime,$allowed)) exit('Bad type');
  $ext = pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION);
  $stored = bin2hex(random_bytes(8)).'.'.$ext;
  $dest = __DIR__.'/uploads/'.$stored;
  move_uploaded_file($tmp,$dest);
  $pdo->exec("USE `{$db}`"); // safe after validation
  $stmt = $pdo->prepare("INSERT INTO `{$table}` (original_name, stored_path, mime, size) VALUES (:o,:p,:m,:s)");
  $stmt->execute([':o'=>$_FILES['image']['name'], ':p'=>'uploads/'.$stored, ':m'=>$mime, ':s'=>filesize($dest)]);
  echo 'OK';
}

Notes and cautions: prefer storing files on disk and paths in the DB (better performance than BLOBs); always whitelist databases/categories instead of letting arbitrary DB names; verify table names against INFORMATION_SCHEMA before using them; set strict upload-size limits, check MIME signatures (not only extensions), store uploads outside the webroot or deny direct access, use HTTPS, and give the DB user minimal privileges. Example uploads table schema:

CREATE TABLE uploads (
  id INT AUTO_INCREMENT PRIMARY KEY,
  original_name VARCHAR(255),
  stored_path VARCHAR(255),
  mime VARCHAR(100),
  size INT,
  uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

These steps close the gaps in the original posts and provide a secure, maintainable way to categorize image uploads by database and table.

Recommended Answers

All 3 Replies

please help

What exactly do you need help with? What do you have so far?

i have a simple upload form and i want to improve it in a way that i can easily categorize the upload process. wherein
I can choose the database and table first before clicking the submit form..

im developing small website wherein i have to upload many images that must be categorize.. for example: CATEGORY_MENS_DB -> Clothes_fashion_TABLE..

wherein i have to get the list of my database and list of its corresponding table.. and put it into select dropdown.. please help..

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.