Jump to content

webguy262

Members
  • Posts

    95
  • Joined

  • Last visited

Posts posted by webguy262

  1. Thanks again for your continued help.

     

    I updated the code and now I get...

     

    1

    2

    Unknown column 'fname' in 'field list'

    5

     

     

     

    The column in the database is player_roster_fname so it is failing on the first insert because only part of the column name is getting iterated.

     

    Do we need this?

     

    $cols = array_keys( $_POST['player'] );
    $cols = array_keys( $_POST['player'][$cols[0]] );

     

    It was in there with the PDO version of the script, but it did not seem to match the code you suggested after learning I did not have PDO installed.

  2. Thanks

     

    Here is what I did...

     

       foreach( $_POST['player'] as $player_id => $player_info ) {
         foreach( $player_info as $k => $v ) {
          $player_info[$k] = "'" . mysql_real_escape_string( $v ) . "'";
          }
          echo "1";
         if( $player_id < 0 ) {
             $player_info['primary_key'] = "'" . mysql_real_escape_string( $player_id ) . "'";
           $stmt = "insert into `rosters` ( " . implode( ', ', array_keys( $player_info ) )
             . " ) values ( " . implode( ', ', $player_info ) . " )";
              echo "2";
          }else{
          foreach( $player_info as $k => $v ) {
             $player_info[$k] = '`' . $k . '`=' . $v;
              echo "3";
          }
          $stmt = "update `rosters` set " . implode( ', ', $player_info ) . " where "
             . "`primary_key`='" . mysql_real_escape_string( $player_id ) . "'";
              echo "4"; 
         }
          mysql_query( $stmt ); // check for errors and success
           echo "5";
        }
       exit(); return; // whatever is appropriate to stop processing
        echo "6";
    }
    

     

    And when I filled in a row, I got this...

     

    125125125125125125125125125125125125125125125

  3. Thanks for continuing to help!

     

    Here's what I have.  When I fill in a row and submit it, I get a no results.  Nothing in the browser; nothing in the database.

     

    Never thought I be disappointed at not seeing an error, but with a blank page, I don't know where to begin trouble  shooting.

     

    Can you take a look?

     

    <?php
    
    if( !empty( $_POST ) ) {
       /**
       * If you print_r( $_POST ) you will find that you have an array named 'players'.
       * Each index into this array will be POSITIVE and the players database ID if they already exist in the database
       * The index will be NEGATIVE if the player is new and needs to be inserted.
       *
       * And then each player is an array where the associative names should match your column names,
       * so that you can easily generate your insert / update statements based on what I
        * showed you earlier.
       */
       foreach( $_POST['player'] as $player_id => $player_info ) {
         foreach( $player_info as $k => $v ) {
          $player_info[$k] = "'" . mysql_real_escape_string( $v ) . "'";
          }
         if( $player_id < 0 ) {
             $player_info['primary_key'] = "'" . mysql_real_escape_string( $player_id ) . "'";
           $stmt = "insert into `rosters` ( " . implode( ', ', array_keys( $player_info ) )
             . " ) values ( " . implode( ', ', $player_info ) . " )";
          }else{
          foreach( $player_info as $k => $v ) {
             $player_info[$k] = '`' . $k . '`=' . $v;
          }
          $stmt = "update `rosters` set " . implode( ', ', $player_info ) . " where "
             . "`primary_key`='" . mysql_real_escape_string( $player_id ) . "'"; 
         }
          mysql_query( $stmt ); // check for errors and success
        }
       exit(); return; // whatever is appropriate to stop processing
    }
    
    echo "<form action=\"roster.php\" method=\"post\"><table>";
       
    $result = mysql_query( $sqlplayers );
    $maxrows = 15;
    $insid = -1;
    // create a blank player template
    $cols = array( 'fname' => 'size="10"', 'lname' => 'size="10"', 'address' => 'size="15"', 'city' => 'size="15"', 'state' => 'size="2"',
       'zip' => 'size="10"', 'phone' => 'size="10"',
       'email' => 'size="20"', 'number' => 'size="2"', 'gradyear' => 'size="4"', 'feet' => 'size="1"', 'inches' => 'size="4"' );
    $blankplayer = array();
    foreach( $cols as $c => $extra ) {
       $blankplayer[$c] = '';
    }
    // we now have a blank player template
    for( $i = 1; $i <= $maxrows; $i++ ) {
       echo "<tr>";
       if( $result ) {
          $player = mysql_fetch_assoc( $result );
        }
       if( !$player ) {
          // We've run out of players, so create a blank one to insert
            $result = null; // stop trying to access result
          $player = $blankplayer;
            $player['id'] = $insid--; // first blank player is id -1, second is -2, third is -3, etc.
       }
       // dump the fields
       foreach( $cols as $c => $extra ) {
          echo "<td>" . tep_draw_input_field( "player[{$player['id']}][{$c}]", $row['player_roster_' . $c], $extra ) ."</td>";
        }
        $player = null; // important!
       echo "</tr>";
        
    }
    ?>
    

  4. Thanks, roopurt18, that seems to have worked for the insert statement. 

     

    But, alas, I'm stuck again.  (Hey, at least I figured out where to echo the <TR></TR> so the form is not longer 180 cells wide!)

     

    I can't figure out how to code the update statement.

     

    I know the basic structure is:

     

    "update rosters set ( " . implode( ', ', $cols ) . " )=( " . implode( ', ', array_fill( 0, count($cols), '?')) . " ) where player_id = $_POST[player_id]"

     

    But obviously that is not going to work as there is no array creating the $cols=$values pairs.

     

    So once again, I need some help.

     

    TIA

  5. Well I think I'm getting close®!

     

    I'm getting the following errors:

     

    Warning: array_keys(): The first argument should be an array in /home/virtual/site57/fst/var/www/html/hoopgroup/roster.php on line 59

    Fatal error: Call to a member function on a non-object in /home/virtual/site57/fst/var/www/html/hoopgroup/roster.php on line 61

     

    I'm not worried about the fatal error as I have not yet added an update statement.  Hopefully, when I get the insert working, creating the update will be easy.

     

    Here is the code...

    if( !empty( $_POST ) ) {
       /**
       * If you print_r( $_POST ) you will find that you have an array named 'players'.
       * Each index into this array will be POSITIVE and the players database ID if they already exist in the database
       * The index will be NEGATIVE if the player is new and needs to be inserted.
       *
       * And then each player is an array where the associative names should match your column names,
       * so that you can easily generate your insert / update statements based on what I
        * showed you earlier.
       */
       $cols = array_keys( $_POST['player'][0] );
       echo '<pre>' . print_r( $_POST, true ) . '</pre>';
       $insert = $pdo->prepare( "insert into rosters ( " . implode( ', ', $cols ) . " ) values ( " . implode( ', ', array_fill( 0, count($cols), '?')) . " )" );
       $update = $pdo->prepare( "an update statement" );
       foreach( $_POST['player'] as $player_id => $player_info ) {
          if( $player_id < 0 ) {
             $insert->execute( $player_info );
          }else{
             $update->execute( $player_info );
            }
        }
       exit(); return; // whatever is appropriate to stop processing
    }
    
    echo "<form action=\"roster.php\" method=\"post\"><table>";
       
    $result = mysql_query( $sqlplayers );
    $maxrows = 15;
    $insid = -1;
    // create a blank player template
    $cols = array( 'fname' => 'size="10"', 'lname' => 'size="10"', 'address' => 'size="15"', 'city' => 'size="15"', 'state' => 'size="2"',
       'zip' => 'size="10"', 'phone' => 'size="10"',
       'email' => 'size="20"', 'number' => 'size="2"', 'gradyear' => 'size="4"', 'feet' => 'size="1"', 'inches' => 'size="4"' );
    $blankplayer = array();
    foreach( $cols as $c => $extra ) {
       $blankplayer[$c] = '';
    }
    // we now have a blank player template
    for( $i = 1; $i <= $maxrows; $i++ ) {
       if( $result ) {
          $player = mysql_fetch_assoc( $result );
        }
       if( !$player ) {
          // We've run out of players, so create a blank one to insert
            $result = null; // stop trying to access result
          $player = $blankplayer;
            $player['id'] = $insid--; // first blank player is id -1, second is -2, third is -3, etc.
       }
       // dump the fields
       foreach( $cols as $c => $extra ) {
          echo "<td>" . tep_draw_input_field( "player[{$player['id']}][{$c}]", $row['player_roster_' . $c], $extra ) ."</td>";
        }
       // echo '<pre>' . print_r( $_POST, true ) . '</pre>';
        $player = null; // important!
    }
    ?>
    </table><input type="submit" name="editplayers" value="Submit" />
    </form>

     

    Thanks again for your help!

  6. Trying to insert arrayed data.

     

    Getting: Parse error: parse error, expecting `']''

     

    Here is the code...

     

    $insert = "INSERT INTO rosters (roster_date, customers_id, player_roster_fname, player_roster_lname, player_roster_address, player_roster_city, player_roster_state, player_roster_zip, player_roster_phone, player_roster_email, player_roster_number, player_roster_gradyear, player_roster_height_feet, player_roster_height_inches) VALUES (CURDATE(), '$customer_id', '$_POST[players[-1][fname]]', '$_POST[players[-1][lname]]', '$_POST[players[-1][address]]', '$_POST[players[-1][city]]', '$_POST[players[-1][state]]', '$_POST[players[-1][zip]]', '$_POST[players[-1][phone]]', '$_POST[players[-1][email]]', '$_POST[players[-1][number]]', '$_POST[players[-1][gradyear]]', '$_POST[players[-1][feet]]', '$_POST[players[-1][inches]]'),

  7. Thanks for continuing to help me with this!  My boss is anxious to have it in place.

     

    I loaded your code and I have a couple of questions...

     

    The cells are coming out like this...

     

    <td><input type="text" name="players[-1][fname]" size="10"></td>

     

    Before I go too far, will the code you suggested process them when they are in that format?  The []'s have me wondering.

     

    Also, where do I add <tr></tr>'s?  I suspect I'll need a count routine, placing them every 12 <td>'s.

     

    I know if needs to go in this area...

     

    foreach( $cols as $c => $extra ) {
          echo "<td>" . tep_draw_input_field( "players[{$player['id']}][{$c}]", $row['player_roster_' . $c], $extra ) ."</td>";
        }

     

    ...but I'm not sure how to code it.

     

    Thanks again!

     

    I'm learning slowly but surely!

  8. Thanks for your help!  I followed your suggestions.

     

    If I understand correctly, the second version of the form creates a single "player" array with all the values for all players.

     

    Then the /* processing the form */ code performs the INSERT, checking to see if the array from a row was empty and if so, not inserting it.

     

    Is that accurate?

     

    How would I handle the INSERT of the two hidden fields: CURDATE() and $customer_id?   

  9. Thanks for your suggestions!  I've managed to do what I want to do, only to discover it can't work that way.

     

    What I dreamed of having was a form with 15 rows.  The rows would be empty if the roster was empty; and if there were players on a roster, they would fill up as many as all 15 of the rows.

     

    All rows would appear in text boxes so editing and adding players would be quite easy.

     

    The problem I've run into is that the extra blank rows create rows in the database even if they are empty.  That because I am inserting an auto increment ID and a date.  So every time the form is submitted, I make 15 new rows.

     

    So I either need to bag the hidden rows, or do the form so that it loads with a single blank row with an "Add" button, meaning people add one player at a time.

     

    Each time a row is added, it would appear in a list above the blank row.  And each of these populated rows would have "Edit" & "Delete" buttons.

     

    Any comments on this approach?

     

  10. I want to allow a coach to create and maintain a roster of 15 players (first name, last name, address, etc.).

     

    To keep it simple, I want to use the same page/form to display an empty roster, as well as one that already has players.

     

    The first time a coach loads the roster page, the form is empty; after entering 1 - 15 players, the form displays them.

     

    The form should also display the existing fields so they can be edited, and should show 15 rows even if the coach has entered fewer players.

     

    Updating values for any existing players, as well as entering values entered into any empty rows, would save upon submit.

     

    Using while($row = mysql_fetch_array($result)) I can displays editable fields for however many players have been entered.

     

    However, I need to get 15 rows and I need to have the field names in each row be different (in order for the INSERT/UPDATE query to work, right?).

     

    I'm trying a while loop with a while loop like this...

     

    $result = mysql_query($sqlplayers);
    $count=14;
    $i=0;
    while($i<=$count) {
    while($row = mysql_fetch_array($result)); {  ?>
    
    <tr>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_fname', $row['player_roster_fname'], 'size="10"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_lname', $row['player_roster_lname'], 'size="10"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_address', $row['player_roster_address'], 'size="15"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_city', $row['player_roster_city'], 'size="15"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_state', $row['player_roster_state'], 'size="2"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_zip', $row['player_roster_zip'], 'size="10"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_phone', $row['player_roster_phone'], 'size="10"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_email', $row['player_roster_email'], 'size="20"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_number', $row['player_roster_number'], 'size="2"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_gradyear', $row['player_roster_gradyear'], 'size="4"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_feet', $row['player_roster_height_feet'], 'size="1"'); ?></td>
    <td><?php echo  tep_draw_input_field('player[$i]_roster_inches', $row['player_roster_height_inches'], 'size="4"'); ?></td></tr>
    
    <?php
    }
    $i++;
    }

     

    This code gives me 15 rows, but the row values are not appearing, and the [$i] in the "player[$i]_roster_inches" is not iterating.

     

    Am I at all on the right track?

     

    Is there another way to do this?

     

    Could really use some help!

  11. I'm trying to get the sum of column A in table X and of column B in table Y.

     

    I need these as two separate sums, not looking to add them together.

     

    Here's what I have, but it is giving wrong results:

     

    Select sum(novo_billing.balance) as sum_balance, sum(novo_payments.payment) as sum_payment from novo_billing, novo_payments

  12. I have a form that generates a part number based upon a series of selection boxes.

     

    http://brinsterinc.com/east/inventory_test.php

     

    I want to pass the part number as a hidden field in a second form that I am going to add to the page. That form will email the part number along with name, email address, etc.

     

    How can I access the part number so that it can be passed as an invisible field?

     

    The code that displays the part number is...

     

    <span name="myspan" id="myspan" style="border:1px solid #000000; padding:2px;"></span>

     

    and the ajax script is...

     

    <script type="text/javascript" language="javascript">
       var http_request = false;
       function makePOSTRequest(url, parameters) {
          http_request = false;
          if (window.XMLHttpRequest) { // Mozilla, Safari,...
             http_request = new XMLHttpRequest();
             if (http_request.overrideMimeType) {
             	// set type accordingly to anticipated content type
                //http_request.overrideMimeType('text/xml');
                http_request.overrideMimeType('text/html');
             }
          } else if (window.ActiveXObject) { // IE
             try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
             } catch (e) {
                try {
                   http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
             }
          }
          if (!http_request) {
             alert('Cannot create XMLHTTP instance');
             return false;
          }
          
          http_request.onreadystatechange = alertContents;
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          http_request.setRequestHeader("Content-length", parameters.length);
          http_request.setRequestHeader("Connection", "close");
          http_request.send(parameters);
       }
    
       function alertContents() {
          if (http_request.readyState == 4) {
             if (http_request.status == 200) {
                //alert(http_request.responseText);
                result = http_request.responseText;
                document.getElementById('myspan').innerHTML = result;            
             } else {
                alert('There was a problem with the request.');
             }
          }
       }
       
       function get(obj) {
          var poststr = "s=" + document.getElementById("s").value + "&it=" + document.getElementById("it").value + "&id=" + document.getElementById("id").value + "&ot=" + document.getElementById("ot").value + "&od=" +  document.getElementById("od").value + "&l=" + document.getElementById("l").value ;makePOSTRequest('post.php', poststr);
       }
    
    </script>

     

     

     

     

  13. Trying to find events prior to today's date, and order them chronologically, either asc or dsc.

     

    Here's what I've got, but they display out of order.

     

    What am I missing?

     

    $today = date("Ymd");
    
    $query = "SELECT title, link, chapter, DATE_FORMAT(start_date, '%M %d,
    %Y') AS start_date, DATE_FORMAT(start_date, 'Ymd') AS chrono, city, state
    FROM events_calendar WHERE start_date < $today  order by chrono";

  14. I am modifying some pages in CRE Loaded.

     

    allprods.php list all currently active products and I added a manufacturers column that displays who makes that product.

     

    I want to allow shoppers to filter the product list so that it shows only products from a particular manufacturer.

     

    I have gone through several scenarios in my mind, but nothing I've thought of seems simple and bullet proof.

     

    One of the issues is that the all products query includes all manufacturers.  If I were to put a variable in the query to select only a particular manufacturer, how would I code it so it does not interfere with the all products query?

     

    Would logic based upon the value of a form action work?  If form action exists, someone wants to filter.  If not form action or form action = all, then they want the whole list.

     

    Seems like filtering a list is pretty common and there should be an easy solution.

     

    Suggestions?

     

    TIA

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.