Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4

Thread: Need help...

  1. #1
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    I am trying to make an upload script for a real estate agent website. This is what I have so far. The script uploads the file but I am trying to write the name of the file into a mysql database table. can some one help me out? I have tried this several different ways and still cant get it to write to the database.

    here is agent_photo.php
    PHP Code:
    <?

    echo"
    <form action='file-upload.php?id=
    $id' method='POST' enctype='multipart/form-data'>

    <input type='hidden' name='MAX_FILE_SIZE' value='10000000'> 
    <input type='hidden' name='id' value='
    $id'> 

    Upload this file:<br>
    <p>
    <input name='userfile[0]' type='file'><br>

    <input type='submit' value='Upload File'>
    </form>
    "
    ;

    ?>
    and here is file-upload.php
    PHP Code:
    <?
    require "config.inc";

    $Dir 'uploads';
    if(!isset(
    $_FILES['userfile'])) die('No File Submitted!');

    for(
    $K 0$K sizeof($_FILES); $K++){
        if(
    $_FILES['userfile']['size'][$K] > $_POST['MAX_FILE_SIZE']) die('The file you submitted is to large!');

        if(!
    copy($_FILES['userfile']['tmp_name'][$K], $Dir '/'$_FILES['userfile']['name'][$K])) die($_FILES['userfile']['error'][$K] . '');

    $db mysql_connect("$dbhost""$dbuser""$dbpassword"); 
    mysql_select_db("$dbname",$db);

       
    $id $_POST['id'];
       
    $upme $_POST['userfile[0]'];
       
            
    $sql "UPDATE agents SET photo='$upme' WHERE id='$id'";
            
    $result mysql_query($sql) or die("update error - " mysql_error()); 

            echo 
    "<center><span class=\"main\">Thank you! Information updated.<p>
            <a href=\"edit_pages.php\">Edit Another Page</a>&nbsp;|&nbsp;
            <a href=\"index.php\">&raquo; Back to Control Panel</a></span></center>"

            
    }

    ?>

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    What happens when it is executed?

    Also,

    PHP Code:
    mysql_select_db("$dbname",$db); 
    should be
    PHP Code:
    mysql_select_db($dbname,$db); 

  4. #3
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    It will upload the file fine but not insert the filename to database. Sometimes i get it insert the word "array" into the database table.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    You're using this as your filename:
    PHP Code:
    $_FILES['userfile']['name'][$K
    Yet you're inserting the results of:
    PHP Code:
    $_POST['userfile[0]'
    Try using the first one for what you're inserting in to the database, too.

    Also, see [phpfunction]move_uploaded_file[/phpfunction] for additional security and checking.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:54 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com