SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with code if (len) syntax error

    I am trying to have the form do this post action if there is something in the field and if empty to skip/ignore

    i am doing this with an if statement say if lenght in post then do this etc...

    before I got an error for unexpected {} should be (), I fixed that now I get this error "syntax error, unexpected T_VARIABLE"

    can any one suggestor know the right code
    PHP Code:
    if (len <=1 $HTTP_POST_FILES['ud_Pic'])
    {
    $ud_Pic=$HTTP_POST_FILES['ud_Pic'];

    I'm pert sure you need to have a numeric value in there maybe the len is wrong???

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to upload a file?

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Read the file upload manual there:http://www.php.net/manual/en/feature...ost-method.php

    First, $HTTP_POST_FILES is deprecated in PHP5+
    Second, you have several information in the second dimension of the $_FILES array, telling you the file name, temporary location, size, mime type and an error code to help recognize why an upload failed (file too big, read only temporary directory, no file specified...)
    PHP Code:
    if ($_FILES['ud_Pic']['size'])>=1)){
      
    $ud_Pic=file_get_content($_FILES['ud_Pic']['tmp_name']);


  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i am doing an update form that will also post if they do not have a pic

    basicilly this is an update form the text types are easy to do the
    PHP Code:
    <input type=text name='ud_Big' value="<? echo "$Big"?>" size=40>
    but file type
    PHP Code:
    <input type=file name='ud_Pic value="<? echo "$pic"?>" size=40>
    do not echo values to update they are blank
    so to avoid database field replacing with an empty value i wrote it like this
    PHP Code:
    <input type=file name='ud_Pic value="" size=40> 
    leaving the value blank so they can still add or change there pic if they choose too

    the problem is if they allready have a pic and are happy with it if they do not reenter it the pic will be lost/replaced by an empty space/field/var/value what ever???

    so my solution to write in the update php an if clause so that if there is nothing in the input field then do not post
    PHP Code:
    if (len <=1 $HTTP_POST_FILES['ud_Pic])
    {
    $ud_Pic=$HTTP_POST_FILES['
    ud_Pic'];

    this if statemnet should post if there is any thing of greater lenth than 1 in the input field and of it is empty 0 then do not post anything...

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($_FILES['ud_Pic']['error'] === UPLOAD_ERR_OK) {
        
    // a file was successfuly uploaded
    } else {
        
    // no upload, or it failed


  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick response but I do not follow that if with the error code will actually stop the posting if it is empty and allow the posting if they want to change or add there pic???

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick response but I do not follow that if with the error code will actually stop the posting if it is empty and allow the posting if they want to change or add there pic???
    No, the error status hold the value relative to the last submit to the server.
    If you want to prohibit the submit if there is no file, you must do that in javascript, not in php.


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
  •