Viper2KX's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
195 (0.09 per day)
Joined:
25-January 09
Profile Views:
8,200
Last Active:
User is offline Jul 11 2014 09:51 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Mac
Favorite Browser:
Safari
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   Viper2KX has not set their status

Posts I've Made

  1. In Topic: Dealing with multiple queries

    Posted 11 Jul 2014

    PDO::lastInsertId() is what I keep on seeing.

    Is that what I need to get this working?
  2. In Topic: Dealing with multiple queries

    Posted 10 Jul 2014

    View Postmacosxnerd101, on 11 July 2014 - 12:47 AM, said:

    Quote

    I included comments saying which executed and which didn't.

    I don't see anything in the comments helpful to me to determine where the logic is failing.

    In line 79/80 at the end.


    View Postmacosxnerd101, on 11 July 2014 - 12:47 AM, said:

    Starting at line 66, which if statements are triggered? Do you understand what I mean by debugging?
    065	            // INSERT INTO `img`
    066	            if(isset($_FILES['imgFile'])) {
    067	                $validExt = array('image/pjpeg', 'image/jpeg', 'image/JPG',
    068	                                  'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
    069	  
    070	                if(in_array($_FILES['imgFile']['type'], $validExt)) {
    071	                    $imgName_N = $_POST['imgName'];
    072	                    $imgName_O = $_FILES['imgFile']['name'];
    073	                    $imgDesc = $_POST['imgDesc'];
    074	                    $imgMime = $_FILES['imgFile']['type'];
    075	                    $imgSize = $_FILES['imgFile']['size'];
    076	                      
    077	                    require_once 'pdo_connect.php';
    078	  
    079	                    $stmt = $dbh->prepare("INSERT INTO img (name_N, name_O, mime, size, uploaded)
    080	                                          VALUES (?, ?, ?, ?, NOW())"); // doesn't execute anymore
    081	                    $stmt->execute(array($imgName_N, $imgName_O, $imgDesc, $imgMime, $imgSize));
    082	  
    083	                    if(move_uploaded_file($_FILES['imgFile']['tmp_name'],
    084	                                          "../gallery/" . $imgName_O)) {
    085	                        echo '<p>
    086	                               <em>The image "' . basename($imgName_O) . '" has been uploaded.</em>
    087	                             </p>';
    088	                    } // end of move
    
    


    Quote

    I know that isn't correct, which could be my problem - I am honestly very unsure where my head was at when I did that.

    Then you should refactor your code to do it correctly.

    Yes, I think (to debugging) -> its super late and my brain has powered off.
    and I will (to refactoring)

    I will work on all this, good start for help. And will come back if I am still stuck.
  3. In Topic: Dealing with multiple queries

    Posted 10 Jul 2014

    I included comments saying which executed and which didn't.
    The entire query related to inserting into the image table doesn't execute.
    Only the insert into album query executes.

    I had phpMyAdmin open and only the album table got filled.

    And also somehow after data got submitted, page would reload. Which doesn't bother me.
    However what does, is my friend's dashboard I had designed similar to this (but with my friend's needs): "Simple Vertical Tab"

    One tab I had named 'Gallery', which houses this form where I need help with the code.
    I would click on that tab and I'd get logged out. My theory is because I have 2 pdo_connect.php scripts required in the same function. I know that isn't correct, which could be my problem - I am honestly very unsure where my head was at when I did that.
  4. In Topic: Dealing with multiple queries

    Posted 10 Jul 2014

    <?php
        function display_upload_form() {
            galleryUpload(); // see below
    ?>
            <form action="" method="post" class="form-horizontal col-md-6"
                  enctype="multipart/form-data" role="form">
                <!-- INSERT INTO `album` table -->
                <div class="form-group">
                    <label for="albumName" class="control-label">Album Name:</label>
                    <input type="text" name="albumName" id="albumName" class="form-control">
                </div>
                <!-- INSERT INTO `img` table -->
                <div class="form-group">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;">
                        </div>
                        <div>
                            <span class="btn btn-default btn-file">
                                <span class="fileinput-new">Select image</span>
                                <span class="fileinput-exists">Change</span>
                                <input type="file" name="imgFile">
                            </span>
                            <a href="#"
                               class="btn btn-default fileinput-exists"
                               data-dismiss="fileinput">
                                Remove
                            </a>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="imgName" class="control-label">Image Name:</label>
                    <input type="text" name="imgName" id="imgName" class="form-control">
                </div>
                <!-- The '''tag system''' INSERT INTO `mediums` table (eventually) -->
                <!-- <div class="form-group">
                    <label for="imgMedium" class="control-label">Medium:</label>
                    <input type="text" name="imgMedium" id="imgMedium" class="form-control">
                </div> -->
                <div class="form-group">
                    <label for="submit" class="control-label"></label>
                    <button type="submit" name="submit" class="btn btn-default">Upload</button>
                </div>
            </form>
    <?php
        }
    ?>
     
    <?php
        function galleryUpload() {
            if($_SERVER['REQUEST_METHOD'] == 'POST') {
     
                // INSERT INTO `album`
                if(!empty($_POST['albumName'])) {
                    $albumName = $_POST['albumName'];
                     
                    require_once 'pdo_connect.php';
     
                    $stmt = $dbh->prepare("INSERT INTO album (title, updated) VALUES (?, NOW())"); // does execute
                    $stmt->execute(array($albumName));
                } else {
                     echo '<p>Please include or select the name of the album.</p>';
                }
                 
                // INSERT INTO `img`
                if(isset($_FILES['imgFile'])) {
                    $validExt = array('image/pjpeg', 'image/jpeg', 'image/JPG',
                                      'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
     
                    if(in_array($_FILES['imgFile']['type'], $validExt)) {
                        $imgName_N = $_POST['imgName'];
                        $imgName_O = $_FILES['imgFile']['name'];
                        $imgDesc = $_POST['imgDesc'];
                        $imgMime = $_FILES['imgFile']['type'];
                        $imgSize = $_FILES['imgFile']['size'];
                         
                        require_once 'pdo_connect.php';
     
                        $stmt = $dbh->prepare("INSERT INTO img (name_N, name_O, mime, size, uploaded)
                                              VALUES (?, ?, ?, ?, NOW())"); // doesn't execute anymore
                        $stmt->execute(array($imgName_N, $imgName_O, $imgDesc, $imgMime, $imgSize));
     
                        if(move_uploaded_file($_FILES['imgFile']['tmp_name'],
                                              "../gallery/" . $imgName_O)) {
                            echo '<p>
                                   <em>The image "' . basename($imgName_O) . '" has been uploaded.</em>
                                 </p>';
                        } // end of move
                    } else {
                        echo '<p>Filetype invalid, please upload in JPEG/JPG or PNG format instead.</p>';
                    }
     
                    // INSERT INTO `mediums`
                }
     
                // error check
                if($_FILES['imgFile']['error'] > 0) {
                    echo '<p>The file could not be uploaded because: <strong>';
                    // print proper error message
                    switch($_FILES['imgFile']['error']) {
                        case 1: print 'The file exceeds the upload_max_filesize.'; break;
                        case 2: print 'The file exceeds the MAX_FILE_SIZE setting.'; break;
                        case 3: print 'The file was only partially uploaded.'; break;
                        case 4: print 'No file was uploaded.'; break;
                        case 6: print 'No temporary folder was available.'; break;
                        case 7: print 'Unable to write to disk.'; break;
                        case 8: print 'File upload stopped.'; break;
                        default: print 'A system error has occurred.'; break;
                    }
                    echo '</strong></p>';
                }
     
                if(file_exists($_FILES['imgFile']['tmp_name']) &&
                   is_file($_FILES['imgFile']['tmp_name'])) {
                    unlink($_FILES['imgFile']['tmp_name']);
                }
            }
        }
    ?>
    
    
  5. In Topic: Dealing with multiple queries

    Posted 10 Jul 2014

    I no longer have access to my code because my work computer is off, but will using a loop work with a single form?

    I've asked on Google+, figured see how helpful they can be (small note, they criticize a lot).
    I know my code isn't the cleanest or

    Quote

    up to par
    for standards - and that is all I got. Well, I didn't want to hear it so I deleted my post for one of the PHP groups on there.

    Anyway, my code can be found here on pastebin because they had asked me to put it on there: [PHP] Multiple Queries

    Well, when submitting the form - only the album.title and album.updated get inserted.
    And nothing gets inserted into the img table.

My Information

Member Title:
D.I.C Head
Age:
24 years old
Birthday:
November 9, 1989
Gender:
Location:
MInneapolis, MN
Full Name:
Andrew Ford
Years Programming:
12
Programming Languages:
Java, VB .NET, HTML, JavaScript, CSS, XHTML

Learning - MySQL, PHP

Contact Information

E-mail:
Private
Website URL:
Website URL  http://
LinkedIn:
http://www.linkedin.com/in/andrewrford