nade93 Posted May 21, 2009 Share Posted May 21, 2009 Hi All I am getting duplicated rows placed when uploading from site to database. the first row is blank and the second row contains the data uploaded. I know it will be a tiny mistake or a comma missing but have traweld for hours and cannot seem to find it my form codes is <form enctype="multipart/form-data" action="upload_file.php" method="POST"><br> <table width="750" cellspacing="4" cellpadding="3" align="center" style="font-size:12px;"><tr><td width="83" bgcolor="eaeaea"> <div align="left"><strong> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> <span style="font-size:12px;"> Upload Photo</span></strong></div></td><td width="641"> <div align="left"> <input name="userfile" type="file" size="70" /> </div></td></tr><tr><td bgcolor="eaeaea"><div align="left"><strong><span style="font-size:12px;">Caption</span></strong></div></td> <td> <div align="left"> <input name="caption" type="text" id="caption" size="70"> </div></td></tr><tr><td bgcolor="eaeaea"><div align="left"><strong><span style="font-size:12px;">description</span></strong></div></td> <td> <div align="left"> <input name="desc" type="text" id="desc" size="70"> </div></td></tr> <tr><td colspan="2" style="padding-right:15px;"><div align="right"> <input type="submit" value="Send File" /> </div></td></tr></table> </form> and my upload form is <?php // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. mysql_connect("", "", "") or die("Could not connect: " . mysql_error()); mysql_select_db(""); $caption = $_REQUEST['caption']; $description = $_REQUEST['desc']; $uploaddir = '../../swf/gallery/asset/3dobject/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $file = '/swf/gallery/asset/3dobject/'. basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "ARGH! the file did not upload!!!!<br>There may be one or two reasons for this:<br><li>File size is too large</li><li>Are you sure its either a jpeg gif or png file?</li>\n"; } echo 'The file uploaded. <a href="http://www.tdhcouture.com/admin/templates/photos_upload.php">Click here to return to the List of Photos</a>'; $res = mysql_query("INSERT INTO photos SET image='$file', caption='$caption', desciption='$description'"); ?> any ideas please?? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 21, 2009 Share Posted May 21, 2009 This is more likely to be a PHP issue. I cannot see anything wrong with your code per-se. The only thing i can think of is that form submits to itself, and you're not checking to see if a form's actually been submitted and are attempting to insert everytime the page loads? Maybe it would help if we saw some more of your code. Quote Link to comment Share on other sites More sharing options...
nade93 Posted May 21, 2009 Author Share Posted May 21, 2009 thats all the code im using unfortunately. its just those two little bits until i can get it right then going to add it to the site Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 I would do what ginger robot said and put an isset on the variables that you are submiting to the database. If that still does not help maybe break the code down to each individual bit i.e try echoing the varaible being submitted and make sure that is all going ok then try setting some variables your self in the php code and try inserting them into the database with out the upload form if they both work its a case of getting them to work together. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 21, 2009 Share Posted May 21, 2009 thats all the code im using unfortunately. its just those two little bits until i can get it right then going to add it to the site Are they in the same file? If so, you definitely need to be adding checks to ensure the form was submitted. Quote Link to comment Share on other sites More sharing options...
nade93 Posted May 21, 2009 Author Share Posted May 21, 2009 they are in seperate files with the ISSET stuff, would that just check the once? where would i need to put that in the code? 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.