herschen Posted November 1, 2007 Share Posted November 1, 2007 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'); } } Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 1, 2007 Share Posted November 1, 2007 Well, instead of just having it echo "Error, query failed", have it tell you why. mysql_query($query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.