biscoe916 Posted March 10, 2008 Share Posted March 10, 2008 Ok so i made a little upload image app, and it works great if there isn't already a picture in the database, otherwise it will just keep putting the same picture into the database over and over, regardless of what picture i choose from my harddrive...... For example: The table is empty with no pictures in it, so i upload image1.jpg. My program then encodes it then stores it into the database. Then I upload image2.jpg it seems to work ok but when i check the database there are just two instances of the first image. This keep going on and on no matter how many different pictures i upload... Just copies the first one over and over. Here is my code: <?php include("auth.php"); // uploadimg.php // By Tyler Biscoe // 09 Mar 2008 // Test file for image uploades include("connect.php"); include("include/header.php"); $max_file_size = 786432; $max_kb = $max_file_size/1024; if($_POST["imgsubmit"]) { if($_FILES["file"]["size"] > $max_file_size) { $error = "Error: File size must be under ". $max_kb . " kb."; } if (!($_FILES["file"]["type"] == "image/gif") && !($_FILES["file"]["type"] == "image/jpeg") && !($_FILES["file"]["type"] == "image/pjpeg")) { $error .= "Error: Invalid file type. Use gif or jpg files only."; } if(!$error) { echo "<div id='alertBox'> Image has been successfully uploaded! </div>"; $handle = fopen($_FILES["file"]["tmp_name"],'r'); $file_content = fread($handle,$_FILES["file"]["size"]); fclose($handle); $encoded = chunk_split(base64_encode($file_content)); $id = $_POST["userid"]; echo $_FILES["file"]["tmp_name"]; $default_exist_sql = "SELECT * FROM members WHERE id='".$id."'"; $default_result = mysql_query($default_exist_sql); $results = mysql_fetch_array($default_result); if(!$results["default_image"]) { $insert_sql = "UPDATE members SET default_image = '$encoded' WHERE id='". $id ."'"; mysql_query($insert_sql); } $sql = "INSERT INTO images (userid, sixfourdata) VALUES ('$id','$encoded')"; mysql_query($sql); } else { echo "<div id='alertBox'>". $error . "</div>"; } } ?> <br /> <font class="heading"> Upload images </font> <br /><br /> <form enctype = "multipart/form-data" action = "<?php $_SERVER['PHP_SELF']; ?>" method = "post" name = "uploadImage"> <input type = "hidden" name="userid" value = "<?php echo $_GET["userid"]; ?>" > <input id="stextBox" type="file" name="file" size="35"><br /> <input type="submit" name="imgsubmit" value="Upload"> </form> <?php include("include/footer.php"); ?> So frustrating!! Quote Link to comment https://forums.phpfreaks.com/topic/95298-image-upload-help/ Share on other sites More sharing options...
DJTim666 Posted March 10, 2008 Share Posted March 10, 2008 Your table must AUTO INCREMENT before you can add multiple lines of data with the same values. Run the following SQL query in your database. ALTER TABLE `members` ADD `id` INT(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY(id) Quote Link to comment https://forums.phpfreaks.com/topic/95298-image-upload-help/#findComment-488117 Share on other sites More sharing options...
biscoe916 Posted March 10, 2008 Author Share Posted March 10, 2008 Thanks for the advice, but i already have a column that is set to primary and auto increment. Here is my table: imgid int(11) auto_increment Primary userid int(11) sixfourdata longtext Quote Link to comment https://forums.phpfreaks.com/topic/95298-image-upload-help/#findComment-488121 Share on other sites More sharing options...
biscoe916 Posted March 10, 2008 Author Share Posted March 10, 2008 Hello? Quote Link to comment https://forums.phpfreaks.com/topic/95298-image-upload-help/#findComment-488182 Share on other sites More sharing options...
biscoe916 Posted March 10, 2008 Author Share Posted March 10, 2008 solved Quote Link to comment https://forums.phpfreaks.com/topic/95298-image-upload-help/#findComment-488192 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.