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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.