SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Resistance is Futile webgodjj's Avatar
    Join Date
    Nov 2002
    Location
    Madison, WI USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form processing with image upload

    Hi, I have been working on a script to put information into a mysql database and upload a file. The user enters informaiton into a form, which passes this to a second page for processing.... Some reason the file information is not entered into the database and is not uploaded... I have been racking my brains for the last 3 hours on this one and need a second pair of eyes...


    Page2.php
    PHP Code:
    <?php
    if (isset($_POST['submit'])) {
    // Update the database
            
    // includes
    include("config.php");

    // open database connection
    $connection mysql_connect($host$user$pass) or die ("Unable to connect!");

    // select database
    mysql_select_db($dbase) or die ("Unable to select database!");

    //upload picture
    if (!empty($_FILES['Menu_pict']['name'])) {
       if ((
    $_FILES['Menu_pict']['type'] == "image/jpeg") || ($_FILES['Menu_pict']['type'] == "image/jpg") || ($_FILES['Menu_pict']['type'] == "image/pjpeg"))
          {
    if ((
    $_FILES['Menu_pict']['size'] < 150*1024)) {
          
    copy ($_FILES['Menu_pict']['tmp_name'], "../images/pictures/".$_FILES['Menu_pict']['name'])
          or die (
    "Could not copy");

          echo 
    "<B>Name:</B> ".$_FILES['Menu_pict']['name']." ";
          echo 
    "<B>Size:</B> ".$_FILES['Menu_pict']['size']." ";
          echo 
    "<B>Type:</B> ".$_FILES['Menu_pict']['type']." ";
          echo 
    "<FONT COLOR=\"CC0000\">Copy Done....</FONT>";
    } else { echo 
    "Your Photo must be less 150k or less in size."; }
        }
       else
        {
          echo 
    "<br><br>";
          echo 
    "You must use jpg formated picutures.  Could Not Copy, Wrong Filetype (".$_FILES['Menu_pict']['name'].")<br>";
          echo (
    $_FILES['Menu_pict']['name']) ."<BR>";
        }
    }
    // End File Upload
    $Menu_pict $_FILES['Menu_pict']['name'];
    //insert into database        
    $SQL="INSERT INTO jimmydean (email, story, Menu_pict, opt_in_spe, timestamp) VALUES ('$email','$story','$Menu_pict','$opt_in_spe',NOW())";
    $result=mysql_query($SQL);

    }
    ?>
    form on index.php

    PHP Code:
              <form name="author_admin" method="post" action="Page2.php">
          <
    table width="300" border="0" cellpadding="5" cellspacing="2" background="images/back_paper.jpg">
        <
    tr>
          <
    td><b><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Email:</font></b>
            <
    input name="email" type="text" size="16"></td>
        </
    tr>
        <
    tr>
          <
    td><b><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Tell
                Us Your Story
    :</font></b><br>
            <
    textarea name="story" cols="30" rows="5"></textarea>
    </
    td>
        </
    tr>
        <
    tr>
          <
    td><p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>and/or
                  
    Submit a Photo:</b></font></p>
            <
    p>
              <
    input name="Menu_pict" type="file" size="24">
          </
    td>
        </
    tr>
        <
    tr>
          <
    td><input type="checkbox" name="opt_in_spe" value="checkbox">
            <
    font face="Verdana, Arial, Helvetica, sans-serif" size="1">YesI would
          like to receive information about future promotions from Orbitz
    .</font> </td>
        </
    tr>
        <
    tr>
          <
    td><div align="center">
            <
    input type="submit" name="submit" value="submit">
          </
    div></td>
        </
    tr>
      </
    table>
          <
    div align="center"><img src="images/orbitz.gif" width="159" height="68">
            </
    div>
          </
    form

  2. #2
    SitePoint Member
    Join Date
    Aug 2003
    Location
    London
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To upload files in a form you need to include the enctype attribute in the form tag.

    <form name="author_admin" method="post" action="Page2.php" enctype="multipart/form-data">

  3. #3
    Resistance is Futile webgodjj's Avatar
    Join Date
    Nov 2002
    Location
    Madison, WI USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have used this form over and over. The only difference here is that the processing happened on a second page. it seems if you process the form on the same page and forgo file checking, you can obmit the file encryption type in the form tag...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •