Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

duplikat baris kosong yang dimasukkan ke mysql pada unggahan file

sejauh yang saya lihat, kode database Anda dijalankan ketika formulir pertama kali dimuat, tetapi belum ada file yang diunggah. Jadi, Anda harus memindahkan kode terkait basis data Anda ke dalam

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))

Seluruh kode:

<?php include 'dbc.php'; page_protect();

if(!checkAdmin()) {header("Location: login.php");
exit();
}

$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
$path   = rtrim($login_path, '/\\');

foreach($_GET as $key => $value) {
    $get[$key] = filter($value);
}

foreach($_POST as $key => $value) {
    $post[$key] = filter($value);
}   
?>

<?php 
if($_FILES['photo']) //check if we uploading a file
{
    $target = "images/test/"; 
    $target = $target . basename( $_FILES['photo']['name']); 

    $title = mysql_real_escape_string($_POST['title']); 
    $desc = mysql_real_escape_string($_POST['desc']);  
    $pic = "images/test/" .(mysql_real_escape_string($_FILES['photo']['name']));
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{
    mysql_query("INSERT INTO `test` (`title`, `desc`, `photo`) VALUES ('$title', '$desc', '$pic')") ;     

    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else 
{ 
    echo "Sorry, there was a problem uploading your file."; 
    var_dump($_FILES); //for debug purposes
}
} 
?> 

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
Title: <input type="text" name="title"><br> 
Description: <input type="text" name = "desc"><br>  
Photo: <input type="file" name="photo"><br> 
<input type="submit" value="Add"> 
</form>



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Cara mengimpor satu tabel ke database mysql menggunakan baris perintah

  2. CURDATE() Contoh – MySQL

  3. pesan berdasarkan XXX urutkan berdasarkan ASC atau DESC , pemesanan dinamis, mysql...

  4. PHP - dapatkan data dari db ke JSON

  5. Bagaimana cara menyimpan Tanggal Java ke Mysql datetime dengan JPA