Jump to content

duplicate rows been placed


nade93

Recommended Posts

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??

Link to comment
https://forums.phpfreaks.com/topic/159062-duplicate-rows-been-placed/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.