Jump to content

MySQL query


herschen

Recommended Posts

Why would this not add data to my database? Please help. There's more to this code than this, but this is where I'm having trouble. This is part of a script for uploading multiple files up to my server. I'm attempting to add the path for these files to my database. For the record, the name of the table I'm inserting into is correct and the names of the columns I am attempting to query are correct. I have not included any of the upload code because it is not causing any problems. In a nut shell, the form creates as many upload form elements as needed, based on the URL parameter passed to $colname_files and when I click upload, it runs all the code after if (isset($_POST['upload_form'])){.

I tried doing the mysql_query in another PHP file, just inserting strings into the database and I always got 'Error, query failed.' What is wrong, please?

 

<?php require_once('../Connections/connProperties.php'); ?> //I have a query on another page using this
                                                                                  // connection; it works fine.


$colname_files = "-1";
if (isset($_GET['image_upload'])) {
  $colname_files = $_GET['image_upload']; //URL parameter, how many files to upload
  }

$colname_files2 = "-1";
if (isset($_GET['propertyid'])) {
  $colname_files2 = $_GET['propertyid'];
  }

//upload directory.
//change to fit your need eg. files, upload .... etc.
$upload_dir = "images";
//number of files to upload.
$num_files = $colname_files;
//the file size in bytes.
$size_bytes =100000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png");


if (isset($_POST['upload_form'])){
for ($i = 1; $i <= $num_files; $i++) {
$new_file = $_FILES['file'.$i];
    $path = $upload_dir . "////" . $new_file['name'];
$query = "INSERT INTO propertiesimages (propertyid, path, picorder) ".
"VALUES ('$colname_files2', '$path', '$i')";

mysql_query($query) or die('Error, query failed'); 
}
}

Link to comment
https://forums.phpfreaks.com/topic/75584-mysql-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.