dennismonsewicz Posted April 1, 2008 Share Posted April 1, 2008 Ok, Here is my situation. I have a SQL query running to insert data into a table field, but when it does it inserts a blank field then inserts the data. Any suggestions? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2008 Share Posted April 1, 2008 Code? Please surround you code with tags. Ken Quote Link to comment Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 Any suggestions? Post the relevent code. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 <?php $_SESSION['username'] = $_GET['username']; if($_POST) { // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. $uploaddir = 'path_to_dir'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $url = 'url_dir' . $_FILES['userfile']['name']; $filename = $_FILES['userfile']['name']; $filesize = $_FILES['userfile']['size']; $filetype = $_FILES['userfile']['type']; $uploaded_by = $_SESSION['username']; $categories = $_POST['categories']; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo '<div class="maincontentheader"> <h2>' . ucwords($_SESSION['username']) . ', thank you for your upload!</h2> </div>'; echo "<p>File is valid, and was successfully uploaded.\n</p>"; } else { echo "<p>Possible file upload attack!\n</p>"; } echo '<p>Below is the information of the file you uploaded:</p>'; echo '<p> Name of File: ' . $filename . '</p>'; echo '<p> Type of File: ' . $filetype . '</p>'; echo '<p> Size of File: ' . $filesize . '</p>'; echo '<p> Categories: ' . $categories . '</p>'; $thumbq = "insert into thumbs (thumb_name) values ('$filename')"; $thumquery = mysql_query($thumbq) or die("ERROR: " . mysql_error()); if($_FILES['userfile']) { include "includes/sql.php"; $query = "insert into uploads (username, name, size, type, url, categories, downloaded_by) " . "values ('$uploaded_by', '$filename', '$filesize', '$filetype', '$url', '$categories', '')"; mysql_query($query) or die("ERROR: " . mysql_error()); echo '<p>File loaded into Database successfully!</p>'; } else { echo '<p>There was a problem with inserting the file into the database! Please try again!</p>'; } } else { echo '<div class="maincontentheader"> <h2>' . ucwords($_SESSION['username']) . ', use the form below to upload an image!</h2> </div> <p>Make sure to add categories to this image.</p> <p> </p> <p>Adding categories allows for the image to show up during an image search!</p> <p> </p> <p>Example Categories: Cat, Dog, Ocean, Older Male, Female, etc...</p> <p> </p> <p style="font-size: 80%"><b>Note: if you have more than one category please make sure to separate them by a comma!</b></p> <p> </p> <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="upload.php?username=' . $_SESSION['username'] . '" method="POST" name="uploadfile"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="9999999" /> <!-- Name of input element determines name in $_FILES array --> <p>Image Categories: <input name="categories" type="text" /></p> <p> </p> <p>Upload this file: <input name="userfile" type="file" /></p> <p><input type="submit" value="Upload File" /></p> </form>'; } //on-th-fly thumbnail generator include "thumbtest.php"; ?> Now the weird thing it is reversed. It is inserting the data and then a blank field :/ it started doing this I moved the include "thumbtest.php" down to the bottom Quote Link to comment Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 So what in thumbtest.php then? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 <?php function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { // open the directory $dir = opendir( $pathToImages ); // loop through it, looking for any/all JPG files: while (false !== ($filename = readdir( $dir ))) { // parse path for the extension $info = pathinfo($pathToImages . $filename); // continue only if this is a JPEG image if ( strtolower($info['extension']) == 'jpg' ) { //echo "Creating thumbnail for {$filename} <br />"; // load image and get image size $img = imagecreatefromjpeg( "{$pathToImages}{$filename}" ); $width = imagesx( $img ); $height = imagesy( $img ); // calculate thumbnail size $new_width = $thumbWidth; $new_height = floor( $height * ( $thumbWidth / $width ) ); // create a new temporary image $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // copy and resize old image into new image imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img, "{$pathToThumbs}{$filename}" ); } } // close the directory closedir( $dir ); } // call createThumb function and pass to it as parameters the path // to the directory that contains images, the path to the directory // in which thumbnails will be placed and the thumbnail's width. // We are assuming that the path will be a relative path working // both in the filesystem, and through the web for links createThumbs("imageuploads/","imageuploads/thumbs/",100); function createGallery( $pathToImages, $pathToThumbs ) { //echo "Creating gallery.html <br />"; $output = "<html>"; $output .= "<head><title>Thumbnails</title></head>"; $output .= "<body>"; $output .= "<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\">"; $output .= "<tr>"; // open the directory $dir = opendir( $pathToThumbs ); $counter = 0; // loop through the directory while (false !== ($filename = readdir($dir))) { // strip the . and .. entries out if ($filename != '.' && $filename != '..') { $output .= "<td valign=\"middle\" align=\"center\"><a href=\"{$pathToImages}{$filename}\">"; $output .= "<img src=\"{$pathToThumbs}{$filename}\" border=\"0\" />"; $output .= "</a></td>"; $counter += 1; if ( $counter % 4 == 0 ) { $output .= "</tr><tr>"; } } } // close the directory closedir( $dir ); $output .= "</tr>"; $output .= "</table>"; $output .= "</body>"; $output .= "</html>"; // open the file $fhandle = fopen( "gallery.html", "w" ); // write the contents of the $output variable to the file fwrite( $fhandle, $output ); // close the file fclose( $fhandle ); } // call createGallery function and pass to it as parameters the path // to the directory that contains images and the path to the directory // in which thumbnails will be placed. We are assuming that // the path will be a relative path working // both in the filesystem, and through the web for links createGallery("imageuploads/","imageuploads/thumbs/"); ?> Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 bump Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 TOPIC SOLVED! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2008 Share Posted April 1, 2008 What was the solution? Ken Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 It is a little difficult to explain, but I pretty much just had to rearrange some of my code and had to add this bit of code: $thumb_name = str_replace("jpg", ".jpg", $info['filename'] . $info['extension']); include "includes/sql.php"; $thumbq = "insert into thumbs (thumb_id, thumb_name) values (NULL, '$thumb_name')"; $thumquery = mysql_query($thumbq) or die("ERROR: " . mysql_error()); the $info var is used from an array reading the files out of the directory the thumbnails are in 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.