herschen Posted November 3, 2007 Share Posted November 3, 2007 Here's my simplified code. I've omitted all the upload testing features and the uploading multiple files feature--this is for testing purposes. As far as I can tell, it's not uploading files successfully, but right now I am trying to update my image database and I am focused on that. I'm passing 'propertyid' from a URL parameter; I've printed this number to the screen and it prints back fine (as the number I inserted into the URL) and also used the is_string function to identify this variable as a string. 'propertyid' in the 'images' table is a foreign key to 'propertyid' in the 'properties' table. When I set 'propertyid' in the URL as '2' (an already existing 'propertyid' in the properties table), and try to query the database, I get an error stating that the column 'propertyid' must be a foreign key to 'propertyid' in the 'properties' table. When I make the value I am inserting into the database '2,' it works fine. If both are strings, why is the first one not working? <?php require_once('../Connections/connProperties.php'); ?> <?php $colname_files = "-1"; if (isset($_GET['image_upload'])) { $colname_files = $_GET['image_upload']; } $colname_files2 = "-1"; if (isset($_GET['propertyid'])) { $colname_files2 = $_GET['propertyid']; } $upload_dir = "images"; if (isset($_POST['upload_form'])){ echo "<h3>Upload results:</h3>"; $i = 1; $new_file = $_FILES['file'.$i]; $file_name = $new_file['name']; $file_name = str_replace(' ', '_', $file_name); $file_tmp = $new_file['tmp_name']; $file_size = $new_file['size']; echo "File $i: ($file_name) Uploaded.<br>"; mysql_select_db($database_connProperties, $connProperties); $path = $upload_dir.$file_name; $i = '1'; $query = "INSERT INTO propertiesimages (propertyid, path, picorder) ". "VALUES ('$colname_file2', '$path', '$picorder')"; mysql_query($query) or die(mysql_error()); echo "»<a href=\"$_SERVER[php_SELF]\">back</a>"; } else{ echo " <h3>Main Images</h3> Max file size = ". $size_bytes / 1024 ." KB"; echo " <form method=\"post\" action=\"$_SERVER[php_SELF]\" enctype=\"multipart/form-data\">"; // show the file input field based on($num_files). $i = 1; echo "Main Image $i: <input type=\"file\" name=\"file". $i ."\"><br>"; echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"> <input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\"> </form>"; } //print copyright ;-) echo"<p align=\"right\"><br>Script by: <a href=\"http://www.maaking.com\">maaking.com</a></p>"; ?> MOD EDIT: code tags added Quote Link to comment Share on other sites More sharing options...
shamsuljewel Posted November 3, 2007 Share Posted November 3, 2007 please submit ur code in the code block..that will help others to read and easily understandable you code... Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2007 Share Posted November 3, 2007 As your form method is POST, put the propertyid value in a hidden form field and pass it that way. Pick it up as $_POST['propertyid']. Your upload code looks fine except for the final step - you need to use move_uploaded_file() to move the file from the temp upload directory to the correct path on the server. There is an example in the "Handling file uploads" section of the manual which deals with multiple uploads without appending those $i to the names. 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.