www.webdeveloper.com
Results 1 to 5 of 5

Thread: No display the message after uploaded Files

  1. #1
    Join Date
    Mar 2007
    Posts
    49

    No display the message after uploaded Files

    my script is uploading the image file in database but it's no show the message
    "Your files is successfully store in database or other Messages". Help Please.Thanks.

    Code:
    <?php
    if ($_POST['Submit']) {
    
    if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
    //print_r($_FILES);
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("test");
    $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));
    
    $query = sprintf("INSERT INTO image(Image, FileType) VALUES('%s', '%s')", $photo, $_FILES['file']['type']);
    if (mysql_query($query)) {
    $messages[] = "Your files is successfully store in database"; 
    } else {
    $messages[]= mysql_error();
    }
    } 
    else {
    $messages[]="The file is bigger than the allowed size please resize";
    }
    }
    ?>
    <html>
    <head>
    <title>Add Image</title>
    </head> 
    <body>
    <? 
    if (isset($messages)) { 
    foreach ($messages as $message) {
    print $message. "<br>" ;
    } 
    }
    ?>
    <form action="" method="post" enctype="multipart/form-data" name="form1">
    <input type="file" name="file">
    <input type="hidden" name="MAX_FILE_SIZE" value="96000">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    I don't see anything immediately wrong with your code. The only thing I can think of is perhaps it is only returning one message so the foreach is pointless. You could try doing a quick check to see if the $messages var is an array or just a single value. If it's an array then foreach them and print them out but, if it's just a single value then skip the foreach and just print it. That's more of a tip than anything I guess. Not sure if it will solve your problem. Doing it that way would make your code more efficient though. Then PHP doesn't have to call up all the foreach stuff for a single value (which is overkill).

    One thing you should check is if your code is spitting out any PHP errors. If you have errors disabled on your server then I'm not sure what you have to do to see the errors. In a log somewhere I would assume. But, if you can find any errors pertaining to your code, that might help us if you post it.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,357
    Could it be the short "<?" tag instead of the "<?php" tag? (The latter always works, the former only if short_open_tags is enabled in your PHP config.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    Yeah, what NogDog said too. You'd be surprised at how often little things like that can blow up in your face.

  5. #5
    Join Date
    Mar 2007
    Posts
    49
    Thanks for your reply. I managed to correct the error. I'm trying to create the script to be able to view the images after been loaded in database.The same concept when we posted how messages in forum. Do you've some guidance? Thank in advance.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles