my code works perfectly for one input box but not the other

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    my code works perfectly for one input box but not the other

    hi all

    have finnaly figured out how this php script works. i have been trying to modify it for some time but i sturgled because i had no idea what the logic behind it was but finally i figured it out and have made it work, almost. the pourpose is for the script to upload and image into a database overighting an older one. this is just used for a super simple content management service. the first form will upload its image and display the new one just fine but the second form (which is identical) wont upload any images my code is below

    [PHP]
    <?
    $host="localhos t"; // Host name.
    $db_user="****" ; // MySQL username.
    $db_password="* ******"; // MySQL password.
    $database="cms" ; // Database name.
    $cms = mysql_pconnect( $host, $db_user, $db_password) or trigger_error(m ysql_error(),E_ USER_ERROR);
    mysql_select_db ($database, $cms);
    $errmsg="";
    if ($_POST[completed] == 'submitted')
    {
    $testval = "set";
    move_uploaded_f ile($_FILES['imagefile']['tmp_name'],"latest.img ");
    $instr = fopen("latest.i mg","rb");
    $image = addslashes(frea d($instr,filesi ze("latest.img" )));
    $location = $_REQUEST[location];
    if (strlen($instr) < 149000) {
    //mysql_query ("INSERT INTO pix (pid, title, imgdata, location) VALUES ('NULL', '$_REQUEST[whatsit]', '$image', '$location')");
    mysql_query("UP DATE pix SET imgdata = '$image' WHERE location='$loca tion'");
    } else {
    $errmsg = "Too large!";
    }
    }


    // below is how my image gets printed
    $page = "home";
    $position = $_REQUEST[gim];
    $locationval = $page . $position;
    $gotten = mysql_query("SE LECT * FROM pix WHERE location='$loca tionval'");

    if ($row = mysql_fetch_ass oc($gotten))
    {
    $bytes = $row[imgdata];
    header("Content-type: image/jpeg");
    print $bytes;
    exit ();
    }
    ?>


    <html><head>
    <title>Upload image</title>

    <center><img src=?gim=1 width=144><br>
    <b></center>
    <form enctype='multip art/form-data' method='post'>
    <input type='hidden' name='MAX_FILE_ SIZE' value='150000'>
    <input type='hidden' name='completed ' value='submitte d'>
    browse: <input type='file' name='imagefile '><br>
    <input type="hidden" name="location" value="home1">
    then: <input type='submit'></form><br>




    <center><img src=?gim=2 width=144><br>
    <b></center>
    <form enctype='multip art/form-data' method='post'>
    <input type='hidden' name='MAX_FILE_ SIZE' value='150000'>
    <input type='hidden' name='completed ' value='1'>
    browse: <input type='file' name='imagefile '><br>
    <input type="hidden" name="location" value="home2">
    then: <input type='submit'></form><br>


    </body>
    </html>

    [/PHP]

    thanks for any input
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    #2
    nevermind i forgot that i change done of the forms for error checking

    eric

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Can happen to anyone.

      Ronald :cool:

      Comment

      Working...