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 12 of 12
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Upload.php page does not work anymore.

    I have a problem with my upload.php page. Form some reason it has stopped working. What I mean by that is it no longer posts to my database table (test). It returns no errors and I am able to echo out the post values from my form. That means the form is working properly so the problem must lie with how my page is handling the post data. I have no memory of modifying this page from the last time it was working. If anyone that is more proficient in PHP than I would be willing to take a look I would appreciate it.

    PHP Code:
    <?php

        $host 
    "localhost";
        
    $user "root";
        
    $db "userdata";
        
    $pass "";
        
        
        
    $odb = new PDO("mysql:host=" $host ";dbname=" $db$user$pass);
        
    $odb->setATTRIBUTE(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
        
        
        if(isset(
    $_POST['Email'], $_POST['Link'], $_POST['Description'], $_POST['Country'], $_POST['State'], $filePath$_POST['Subscription'], $_POST['stripeToken'], $_FILES['uploaded_file'])) {
             
    $Email $_POST['Email'];
             
    $Link $_POST['Link'];
             
    $Description $_POST['Description'];
             
    $Country $_POST['Country'];
             
    $State $_POST['State'];
             
    $Image $filePath;
             
    $Sub $_POST['Subscription'];
             
    $token $_POST['stripeToken'];
             echo 
    $_FILES['uploaded_file'];
                echo 
    $token;
                
            
    $fileName $_FILES["uploaded_file"]["name"]; // The file name
            
    $uploadDir 'uploads/resized_'//upload directory
            
    $filePath $uploadDir $fileName// file path/completed directory
        
            
    $q "INSERT INTO test(Email, Link, Country, State, Description, Image_directory, Subscription, token) VALUES(:Email, :Link, :Country, :State, :Description, :filePath, :Subscription, :stripeToken)";
            
    $query $odb->prepare($q);
            
    $results $query->execute(array(
                
    ":Email" => $Email,
                
    ":Link"  => $Link,
                
    ":Country" => $Country,
                
    ":State"    => $State,
                
    ":Description"     => $Description,
                
    ":filePath" => $Image,
                
    ":Subscription" => $Sub,
                
    ":stripeToken" => $token,
                
            ));
        

        
        
        
        

    //Image upload and error handling
    // Access the $_FILES global variable for this specific file being uploaded
    // and create local PHP variables from the $_FILES array of information
    $fileName $_FILES["uploaded_file"]["name"]; // The file name
    $fileTmpLoc $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
    $fileType $_FILES["uploaded_file"]["type"]; // The type of file it is
    $fileSize $_FILES["uploaded_file"]["size"]; // File size in bytes
    $fileErrorMsg $_FILES["uploaded_file"]["error"]; // 0 = false | 1 = true
    $kaboom explode("."$fileName); // Split file name into an array using the dot
    $fileExt end($kaboom); // Now target the last array element to get the file extension
    // START PHP Image Upload Error Handling --------------------------------------------------
    if (!$fileTmpLoc) { // if file not chosen
        
    echo "ERROR: Please browse for a file before clicking the upload button.";
        exit();
    } else if(
    $fileSize 5242880) { // if file size is larger than 5 Megabytes
        
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
        
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
        
    exit();
    } else if (!
    preg_match("/.(gif|jpg|png)$/i"$fileName) ) {
         
    // This condition is only if you wish to allow uploading of specific file types    
         
    echo "ERROR: Your image was not .gif, .jpg, or .png.";
         
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
         
    exit();
    } else if (
    $fileErrorMsg == 1) { // if file upload error key is equal to 1
        
    echo "ERROR: An error occured while processing the file. Try again.";
        exit();
    }
    // END PHP Image Upload Error Handling ----------------------------------------------------
    // Place it into your upload folder mow using the move_uploaded_file() function
    $moveResult move_uploaded_file($fileTmpLoc"uploads/original/$fileName");
    // Check to make sure the move result is true before continuing
    if ($moveResult != true) {
        echo 
    "ERROR: File not uploaded. Try again.";
        
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
        
    exit();
    }
    //unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
    // ---------- Include Adams Universal Image Resizing Function --------
    include_once("ak_php_img_lib_1.0.php");
    $target_file "uploads/original/$fileName";
    $resized_file "uploads/resized_$fileName";
    $wmax 100;
    $hmax 350;
    ak_img_resize($target_file$resized_file$wmax$hmax$fileExt);
    // Run the function again with new parameter values
    $newname "uploads/original/$fileName";
    $resized_file "uploads/l_resized/$fileName";
    $wmax 400// change sizes to new size
    $hmax 1000// change sizes to new size
    ak_img_resize($target_file$resized_file$wmax$hmax$fileExt);
    // ----------- End Adams Universal Image Resizing Function -----------

    // Display things to the page so you can see what is happening for testing purposes
    /*echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
    echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
    echo "It is an <strong>$fileType</strong> type of file.<br /><br />";
    echo "The file extension is <strong>$fileExt</strong><br /><br />";
    echo "The Error Message output for this upload is: $fileErrorMsg";*/
    //mysql_close($con);
    //header('Location: [url]http://localhost/Submitted_successfully.html');[/url]
    }
    ?>
    Last edited by Ax3l; 01-01-2013 at 03:33 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Are you sure you haven't modified it recently? I recall posting in the mysql forum for a PDO question you have on binding, and you are using the prepared statements here.
    Does it successfully move the file to the uploads/original/$fileName location? Make sure you enable error reporting as well (in case you don't have PDO capability or valid mysql drivers for PDO):
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    Also, check the $result. If its true, it was successful, so you can then check the $query->rowCount(). I think that's right (Dormlich is the resident PDO expert )
    Last edited by Fou-Lu; 01-01-2013 at 03:44 PM.

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Are you sure you haven't modified it recently? I recall posting in the mysql forum for a PDO question you have on binding, and you are using the prepared statements here.
    Does it successfully move the file to the uploads/original/$fileName location? Make sure you enable error reporting as well (in case you don't have PDO capability or valid mysql drivers for PDO):
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    Also, check the $result. If its true, it was successful, so you can then check the $query->rowCount(). I think that's right (Dormlich is the resident PDO expert )
    That question was for a different page. I had this one working a while before that. And no, it does not move the file anymore, do you see an error with it?

  • #4
    New Coder
    Join Date
    Aug 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ax3l View Post
    That question was for a different page. I had this one working a while before that. And no, it does not move the file anymore, do you see an error with it?
    I have a Fatal error:

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Email' cannot be null' in C:\xampp\htdocs\uploadPDO.php:44 Stack trace: #0 C:\xampp\htdocs\uploadPDO.php(44): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\uploadPDO.php on line 44
    PHP Code:
    $q "INSERT INTO test (Email, Link, Country, State, Description, Image_directory, Subscription, token) VALUES(:Email, :Link, :Country, :State, :Description, :filePath, :Subscription, :stripeToken)";
            
    $query $odb->prepare($q);
            
    $results $query->execute(array(
                
    ":Email" => $Email,
                
    ":Link"  => $Link,
                
    ":Country" => $Country,
                
    ":State"    => $State,
                
    ":Description"     => $Description,
                
    ":filePath" => $Image,
                
    ":Subscription" => $Sub,
                
    ":stripeToken" => $token,
                
    line #44        )); 
    Last edited by Ax3l; 01-01-2013 at 04:46 PM.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The usage looks right to me. The isset check verifies that you have an email option, and it extracts from the same.
    Check your HTML form that it creates. The only thing I can think of with this is that you have 2x input types named email, the second of which is the one that will win. Of course, this assumes that you have actually filled out the form since you need to do that as well.

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Might be this extra comma

    ":stripeToken" => $token, <<< here
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Extra commas usually don't matter in arrays, but I could see it being a problem when passed to an external resource like a prepared statement. The error doesn't really clarify (where's Dorm :P).

  • #8
    New Coder
    Join Date
    Aug 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Extra commas usually don't matter in arrays, but I could see it being a problem when passed to an external resource like a prepared statement. The error doesn't really clarify (where's Dorm :P).
    It wasn't the comma. I've since gotten it to work. It had something to do with the isset function.

    I changed:
    PHP Code:
      ":Email" => $Email,
                
    ":Link"  => $Link,
                
    ":Country" => $Country,
                
    ":State"    => $State,
                
    ":Description"     => $Description,
                
    ":filePath" => $Image,
                
    ":Subscription" => $Sub,
                
    ":stripeToken" => $token
    to this:
    PHP Code:
        ":Email" => $_POST['Email'],
                
    ":Link"  => $_POST['Link'],
                
    ":Country" => $_POST['Country'],
                
    ":State"    => $_POST['State'],
                
    ":Description"     => $_POST['Description'],
                
    ":filePath" => $filePath,
                
    ":Subscription" => $_POST['Subscription'],
                
    ":stripeToken" => $_POST['stripeToken'
    and now it works.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by Ax3l View Post
    It wasn't the comma. I've since gotten it to work. It had something to do with the isset function.

    I changed:
    PHP Code:
      ":Email" => $Email,
                
    ":Link"  => $Link,
                
    ":Country" => $Country,
                
    ":State"    => $State,
                
    ":Description"     => $Description,
                
    ":filePath" => $Image,
                
    ":Subscription" => $Sub,
                
    ":stripeToken" => $token
    to this:
    PHP Code:
        ":Email" => $_POST['Email'],
                
    ":Link"  => $_POST['Link'],
                
    ":Country" => $_POST['Country'],
                
    ":State"    => $_POST['State'],
                
    ":Description"     => $_POST['Description'],
                
    ":filePath" => $filePath,
                
    ":Subscription" => $_POST['Subscription'],
                
    ":stripeToken" => $_POST['stripeToken'
    and now it works.
    Lols, that makes *no* sense at all. It shouldn't matter if its $_POST['Email'] or $Email since both are in scope here. Sometimes you cannot use an array for a few things, such as for a reference, but its usually that way where arrays are no good and must be a variable (regardless of using other references to use a variable within an array).
    Try changing that back to just $Email. Does that still work?

  • #10
    New Coder
    Join Date
    Aug 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Lols, that makes *no* sense at all. It shouldn't matter if its $_POST['Email'] or $Email since both are in scope here. Sometimes you cannot use an array for a few things, such as for a reference, but its usually that way where arrays are no good and must be a variable (regardless of using other references to use a variable within an array).
    Try changing that back to just $Email. Does that still work?
    I think changing it back worked because the syntax of my isset function was wrong. Using $Email worked just now, but only after changing the isset.

  • #11
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You have been alternating between a variable named $Image and one called $filePath. At one point (in your first code) you assign $filePath a new value, but then revert to using $Image.

    I don't know whether this is an issue but it is worth checking and revising if appropriate.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #12
    New Coder
    Join Date
    Aug 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AndrewGSW View Post
    You have been alternating between a variable named $Image and one called $filePath. At one point (in your first code) you assign $filePath a new value, but then revert to using $Image.

    I don't know whether this is an issue but it is worth checking and revising if appropriate.
    I do think you are correct. I took $Image out of the isset funtion and set:
    PHP Code:
    ":filePath" => $filePath
    instead of:
    PHP Code:
    ":filePath" => $Image
    The code now looks like:
    PHP Code:
    if (isset($_POST['Email'], $_POST['Link'], $_POST['Country'], $_POST['State'], $_POST['Description'], $_POST['Subscription'], $_POST['stripeToken'])) {
            
    $Email $_POST['Email'];
            
    $Link $_POST['Link'];
            
    $Country $_POST['Country'];
            
    $State $_POST['State'];
            
    $Description $_POST['Description'];
            
    $Subscription $_POST['Subscription'];
            
    $token $_POST['stripeToken'];
        

            
    $fileName $_FILES["uploaded_file"]["name"]; // The file name
            
    $uploadDir 'uploads/resized_'//upload directory
            
    $filePath $uploadDir $fileName// file path/completed directory
        
            
    $q "INSERT INTO test (Email, Link, Country, State, Description, Image_directory, Subscription, token) VALUES(:Email, :Link, :Country, :State, :Description, :filePath, :Subscription, :stripeToken)";
            
    $query $odb->prepare($q);
            
    $results $query->execute(array(
                
    ":Email" => $Email,
                
    ":Link"  => $Link,
                
    ":Country" => $Country,
                
    ":State"    => $State,
                
    ":Description"     => $Description,
                
    ":filePath" => $filePath,
                
    ":Subscription" => $Subscription,
                
    ":stripeToken" => $token
                
            
    ));

    and is working.


  •  

    Tags for this Thread

    Posting Permissions

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