Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    What is wrong with this code

    I have no idea what is wrong with this code... if someone could help me that would be great it would be so awesome!
    PHP Code:
    <html>  
    <body>  
    <?php  
    $input2 
    $_POST["Name"];    
    $input3 $_POST["Email"];   
    $input4 $_POST["time"];   
    $input5 $_POST["TermsOfService"];  
    $input6 $_POST["3p42r3ad3a4than32"];   
    $input7 $_POST["Title"];    
    $input8 $_POST["Description"];    
    $input9 $_POST["file1"];   
    $input10 $_POST["file2"];   
    $empty '';  
    $agree 'Agreed';  
    $a '329r8g';  

    ?>  
    <?php  
    $c 
    '1';  
    $d '0';  
    $valid '5';  
    if (
    $empty == $input2) {  
            echo 
    "Your Name cannot be blank.<br>";  
    } else {  
    ++
    $d;  
    }  

    if (
    $empty == $input3) {  
            echo 
    "Your EmailAddress cannot be blank.<br>";  
    } else {  
    ++
    $d;  
    }  
    if (
    $empty == $input4) {  
            echo 
    "Make sure your clock is set to the correct date, we record dates so we can know exactly when you submitted your files...<br>";  
    } else {  
    ++
    $d;  
    }  
    if (
    $empty == $input5) {  
            echo 
    "You must agree to the Terms Of Service.<br>";  
    } else {  
    ++
    $d;  
    }  
    if (
    $empty == $input6) {  
            echo 
    "There is an error with our form we are sorry for this problem we will fix it tomorrow.<br>";  
    } else {  
    ++
    $d;  
    }  
    if (
    $d == $valid){  
    $upload_dir "submitions/";   
    $num_files 2;   
    //the file size in bytes.   
    $size_bytes =20480000//51200 bytes = 50KB.   
    //Extensions you want files uploaded limited to.   
    $limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");   


       
    //check if the directory exists or not.   
       
    if (!is_dir("$upload_dir")) {   
          die (
    "Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");   
       }   
       
    //check if the directory is writable.   
       
    if (!is_writeable("$upload_dir")){   
          die (
    "Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");   
       }   


    //if the form has been submitted, then do the upload process   
    //infact, if you clicked on (Upload Now!) button.   
    if (isset($_POST['upload_form'])){   

           echo 
    "<h3>Upload results:</h3>";   

           
    //do a loop for uploading files based on ($num_files) number of files.   
           
    for ($i 1$i <= $num_files$i++) {   

               
    //define variables to hold the values.   
               
    $new_file $_FILES['file'.$i];   
               
    $file_name $new_file['name'];   
               
    //to remove spaces from file name we have to replace it with "_".   
               
    $file_name str_replace(' ''_'$file_name);   
               
    $file_tmp $new_file['tmp_name'];   
               
    $file_size $new_file['size'];   

               
    #-----------------------------------------------------------#   
               # this code will check if the files was selected or not.    #   
               #-----------------------------------------------------------#   

               
    if (!is_uploaded_file($file_tmp)) {   
                  
    //print error message and file number.   
                  
    echo "File $i: Not selected.<br>";   
               }else{   

                     
    $ext strrchr($file_name,'.');   
                     if (!
    in_array(strtolower($ext),$limitedext)) {   
                        echo 
    "File $i: ($file_name) Wrong file extension. <br>";   
                     }else{   


                           if (
    $file_size $size_bytes){   
                               echo 
    "File $i: ($file_name) Faild to upload. File must be <b>"$size_bytes 1024 ."</b> KB. <br>";   
                           }else{   
                            

                                 if(
    file_exists($upload_dir.$file_name)){   
                                     echo 
    "File $i: ($file_name) already exists.<br>";   
                                 }else{   
                                   
                                       if (
    move_uploaded_file($file_tmp,$upload_dir.$file_name)) {   
                                           echo 
    "File $i: ($file_name) Uploaded.<br>";   
                                       }else{   
                                            echo 
    "File $i: Faild to upload.<br>";   
                                       }
    #end of (move_uploaded_file).   

                                 
    }#end of (file_exists).   

                           
    }#end of (file_size).   

                     
    }#end of (limitedext).   

               
    }#end of (!is_uploaded_file).   

           
    }#end of (for loop).   
           # print back button.   
           
    echo "»<a href=\"$_SERVER[PHP_SELF]\">back</a>";   
    ////////////////////////////////////////////////////////////////////////////////   
    //else if the form didn't submitted then show it.   
    }else{   
        echo 
    " <h3>Select files to upload!.</h3>   
               Max file size = "
    $size_bytes 1024 ." KB";   
        echo 
    " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";   
               
    // show the file input field based on($num_files).   
               
    for ($i 1$i <= $num_files$i++) {   
                   echo 
    "File $i: <input type=\"file\" name=\"file"$i ."\"><br>";   
               }   
        echo 
    " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">   
               <input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">   
               </form>"
    ;   
    }   
    $data "<table border='1'>  
    <tr><td>User IP Address:</td><td>$input1</td></tr>  
    <tr><td>Name:</td><td>$input2</td></tr>  
    <tr><td>Email Address:<td>$input3</td></tr>  
    <tr><td>Date Submitted:</td><td>$input4</td></tr>  
    <tr><td>Description</td><td><textarea cols='50' rows='5'>$input6</textarea></td></tr>  
    <tr><td>File 1 Location:</td><td>$file1</td></tr>  
    <tr><td>File 2 Location:</td><td>$file2</td></tr></table>"
    ;   


    if (
    is_writable($filename)) {   
        if (!
    $handle fopen($filename'a')) {   
             echo 
    "Cannot open file ($filename)";   
             exit;   
        }   

        
    // Write $somecontent to our opened file.   
        
    if (fwrite($handle$data) === FALSE) {   
            echo 
    "Cannot write to file";   
            exit;   
        }   

        echo 
    "Success your information has been submitted!  Now please submit your files...";   

        
    fclose($handle);   

    }   
    } else{  
     echo 
    "You must fill out all fields properly";  
    }
    Thanks

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Mr Mechanic, what is wrong with my car?

    If you want to know "what's wrong" with the code, you have to tell us what you wanted to have happen or expected to happen, what did or did not happen as expected, and any error messages you received.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Mr Mechanic, what is wrong with my car?
    Oh sorry, my bad lol...
    Ok so everything works till I get to the last validation which is this:
    Code:
    if ($d == $valid){
    What is supposed to happen is that when d equals the value of valid then it shows the upload form and then submits the data from the previous page... *which is everything past this*
    Code:
    if ($d == $valid){
    The validation process works, just when everythings valid it doesn't show anything on the page...

    Please if someone could help that would be awesome!
    Last edited by rockonmetal; 08-30-2007 at 09:45 PM.

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If someone could help me that would be great!!!!!
    Thanks!

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Are you sure $d is being incremented? I'm pretty sure your plus symbols are on the wrong side of the variable, ie, it should be $d++;

  • Users who have thanked Pennimus for this post:

    rockonmetal (08-30-2007)

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Let me try that, but I know when I was testing to see if it worked it did add it up...

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks!!!!!! IT WORKS!!!!

  • #8
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Interesting... other languages provide ++var as a way to increment before the expression is evaluated, but I guess PHP does not.

  • #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    blah i wouldnt waste your time Fum.. take a look at his last thread, i try help him and he got rude... F him..

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    (From the manual)

    ++$a Pre-increment Increments $a by one, then returns $a.
    $a++ Post-increment Returns $a, then increments $a by one.
    --$a Pre-decrement Decrements $a by one, then returns $a.
    $a-- Post-decrement Returns $a, then decrements $a by one.

  • #11
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Hrmm yeah I thought PHP would support ++$var... guess the OP is a little confused as to what fixed his code.


  •  

    Posting Permissions

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