sponsored links

Collapse

Announcement

Collapse
No announcement yet.

PHP Newbie needs help with checkbox selection program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Newbie needs help with checkbox selection program

    I'm a newbie to php I'm trying to write an application where a user selects multiple orders via a check box and all of the orders selected get written to a detail file. The next display lists a table of all the orders selected so the user can prioritize them. I also have a header screen program where the user enters the date, type, and manpower and writes that info to the header file. That write is being done in the beginning of this program. The problem is when I select the orders I am getting an error at the beginning of the code and when I echo the variables $date and $type are getting the value of ARRAY and the program is giving me an error on the SQL. I either need a way to skip over the top selection code or is there a way I can pass the array fields of the selected items to a third program that does the updates and displays the third screen. Here is the code. I took a PHP class about 4 years ago and haven't done much since so I'm at a loss here. If you can help me figure out how to do this I would appreciate it.
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php
     
    // Program name---->>>  shipestimate.php
    //                      This program is used to display orders ready for shipping. 
    // Author name----->>>  Mary Beth Hamel
    // Date written---->>>  05/28/14
       
     
    session_start();  // start the session
     
    ini_set('max_execution_time'0);
    ?>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <link href="css/Luster1.css" rel="stylesheet" type="text/css" />
    <link href="css/header.css" rel="stylesheet" type="text/css" />
    <link href="css/menu.css" rel="stylesheet" type="text/css" />
    <link href="css/footer.css" rel="stylesheet" type="text/css" />

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <head>
    <title>Orders On the Dock</title>
    </head>
        
    <?php    
    require_once ('C:/wamp/db/login.php');

    // Try to connect to database
    try
    {
    $db = new PDO($db_hostname$db_user$db_pass);
    }
    catch (
    PDOExcepton $e)
    {
    echo 
    $e->getMessage();
    exit();
    }
    $db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);

    // check variables selected and insert data into header
    if (isset($_POST['manpower']))
      {
      
    $manpower $_POST['manpower'];
      }
      if (isset(
    $_POST['type']))
      {
      
    $type $_POST['type'];
      }
      if (isset(
    $_POST['date']))
      {
      
    $date $_POST['date'];
      }
     
    if (isset(
    $_POST['date']))
    {
    echo 
    "date is " $date;
    echo 
    "type is " $type;
    // Insert data into header if does not already exist if it does exist update Manpower. 
    $selstring "Select Count(*) From LPCUSTTST.OPPSHEHD where shehdat = $date and shehtyp = '$type'";
    $s $db->prepare("$selstring"); 
    $s->execute();

    if(
    $Count == 0) {
    $selstring "INSERT INTO LPCUSTTST.OPPSHEHD(shehdat, shehtyp, shehmanp) VALUES($date,'$type','$manpower')";
    $s $db->prepare("$selstring"); 
    $s->execute();
    }
    else
    {
    $selstring "UPDATE LPCUSTTST.OPPSHEHD(shehmanp) Values('$manpower')";
    $s $db->prepare("$selstring"); 
    $s->execute();
    }
    }
    $DATE $date;
    $TYPE $type;
    ?>

    <body>
    <h3>Orders On the Dock</h3>
    <form name="OrderInquirySelectionForm" method="POST" action="ShipEstimate.php">
          Position To :
          <input name="Pmptname" type="text" value="<?php echo $Pmptname;?>">
          <input name="BtnSubmit" type="submit" value="Submit">
          <br/><br/>
          Sequence By :
          <input name="chck" type="radio" <?php if (isset($chck) && $chck=="O") echo "checked";?> value="O"> Order #
          <input name="chck" type="radio" <?php if (isset($chck) && $chck=="A") echo "checked";?> value="A"> Customer
          <input name="chck" type="radio" <?php if (isset($chck) && $chck=="S") echo "checked";?> value="S"> Ship Date
          <br/><br/>
    </form>
        <form name="form1" method="post" target='_self'>
         <table border="1">
            <tr class="bar" bgcolor='#CC9933'>
            <th width='50' align='center' bgcolor='#7F462C'>Select</th>
            <th width='200' align='center' bgcolor='#7F462C'>Order #</th>
            <th width='200' align='center' bgcolor='#7F462C'>BO #</th>
            <th width='300' align='center' bgcolor='#7F462C'>Customer</th>
            <th width='100' align='center' bgcolor='#7F462C'>Sch Ship Date</th>
            <th width='100' align='center' bgcolor='#7F462C'>Ordered Cases</th>
            <th width='100' align='center' bgcolor='#7F462C'>Picked Cases</th>
            <th width='100' align='center' bgcolor='#7F462C'>Cases To Pick</th>
            <th width='100' align='center' bgcolor='#7F462C'>Wrapped Cases</th>
            <th width='100' align='center' bgcolor='#7F462C'>Total Pallets</th>
            <th width='100' align='center' bgcolor='#7F462C'>Full Pallets</th>
            <th width='100' align='center' bgcolor='#7F462C'>F.P. Percent</th>
            <th width='100' align='center' bgcolor='#7F462C'>Total Weight</th>
            </tr>
            
    <?php
          
    if (isset($_POST['BtnSubmit'])) 
        {
        
            if (empty(
    $_POST['Pmptname']))
            {
                If (
    $_POST['chck'] == 'S')
                {
                
    $Pmptname 0;
                }
                else
                {
                
    $Pmptname "' '";
                }
            }
            else
            {
            
    $Pmptname $_POST['Pmptname'];
            
    $Pmptname "'$Pmptname'";
            }
            
            if (isset(
    $_POST['chck']))
            {
            
    $chck $_POST['chck'];
            }
            else
            {
            
    $chck 'N';
            }
                    
        }    
        else
        {
        
    $chck 'N';
        
    $Pmptname "' '";
        }    
        
     
    $selstring "SELECT DISTINCT OHORD, OHBORD, OHSCUS, OHSAD1, OHPRDT, SHOCAS, SHSKID, SHEWGT, SHFSKD FROM OPDBFA.OPPOHD, LPCUST.OPPCOT, LPCUST.OPPSHOHD WHERE OHORD = SHORDN AND OHBORD = SHBORD AND OHTYPE = OTTYPE AND OTPKSH = '1' AND OHSTAT <> 'RFI' AND OHSTAT <> 'RFR' AND OHTYPE <> 'TFR' AND OHHOLD <> '1' AND OHLOC='001  ' AND OHCO='  001' AND OHUHLD <> 'CANCL' AND OHBORD = '00' AND OHRLDT > 0";
       
     If (
    $chck == 'O')
     {
     
    $selstring "$selstring AND OHORD >= $Pmptname ORDER BY OHORD, OHBORD";
     }
     If (
    $chck == 'A')
     {
     
    $selstring "$selstring AND OHSCUS >= $Pmptname ORDER BY OHSCUS, OHPRDT";
     }
     If (
    $chck == '
     S'
    )
     {
     
    $selstring "$selstring AND OHPRDT >= $Pmptname ORDER BY OHPRDT, OHSAD1";
     }
     If (
    $chck == 'N')
     {
     
    $selstring "$selstring AND OHSAD1 >= $Pmptname ORDER BY OHSAD1, OHPRDT";
     }
     
    $rowclass 0;
     
    $LINE 0;
     
    $s $db->prepare("$selstring"); 
     
    $s->execute();
     while(
    $r $s->fetch(PDO::FETCH_ASSOC))
     {
      
    $total $s->rowCount();
      
    $OHORD  $r[OHORD];
      
    $OHBORD  $r[OHBORD];
      
    $OHSCUS $r[OHSCUS];
      
    $OHSAD1 $r[OHSAD1];  
      
    $OHPRDT $r[OHPRDT];
      
    $SHOCAS $r[SHOCAS];
      
    $SHSKID $r[SHSKID];
      
    $SHEWGT $r[SHEWGT];
      
    $SHFSKD $r[SHFSKD];
      
    $CUST $OHSCUS '-' $OHSAD1
      
    $OHPRMDY substr($OHPRDT,4,2). '-' .substr($OHPRDT,6,2).'-'.substr($OHPRDT,0,4);
      
    $SHEWGT number_format($SHEWGT2);
    IF (
    $SHSKID <= 0
     {
     
    $FPPCT 0;
     }
     
     else
     {
     
    $FPPCT = ($SHFSKD $SHSKID);
     
    $FPPCT = ($FPPCT 100); 
     
    $FPPCT number_format($FPPCT0);
     } 
     
     
    $class " 'altcol$rowclass' "
    ?>

    <tr class="<?php echo $class;?>">
    <td class="text"><input name="checkbox[]" type="checkbox" id="checkbox" value =<?php echo $LINE;?>></td>
    <td class="text"><input name ="ohord[]" type="text" readonly ="readonly" value = <?PHP echo $OHORD;?>></td>
    <td class="text"><input name ="ohbord[]" type = "text" readonly ="readonly" value = <?PHP echo $OHBORD;?>></td>
    <td class="text"><input name ="cust[]" type = "text" readonly ="readonly" value = <?PHP echo $CUST;?>></td>
    <td class="text"><input name ="ohprmdy[]" type = "text" readonly="readonly" value = <?PHP echo $OHPRMDY;?>></td>
    <td class="text"><input name ="shocas[]" type = "text" readonly="readonly" value = <?PHP echo $SHOCAS;?>></td>
    <td class="text"><input name ="pkqty[]" type = "text" readonly="readonly" value = <?PHP echo $PKQTY;?>></td>
    <td class="text"><input name ="lftpck[]" type = "text" readonly="readonly" value = <?PHP echo $LFTPCK;?>></td>
    <td class="text"><input name ="wrpqty[]" type = "text" readonly="readonly" value = <?PHP echo $WRPQTY;?>></td>
    <td class="text"><input name ="shskid[]" type = "text" readonly="readonly" value = <?PHP echo $SHSKID;?>></td>
    <td class="text"><input name ="shfskd[]" type = "text" readonly="readonly" value = <?PHP echo $SHFSKD;?>></td>
    <td class="text"><input name ="fppct[]" type = "text" readonly="readonly" value = <?PHP echo $FPPCT;?>></td>
    <td class="text"><input name ="shewgt[]" type = "text" readonly="readonly" value = <?PHP echo $SHEWGT;?>></td>
    <td class="text"><input name ="date[]" type="hidden" value<?php echo $DATE;?>></td>
    <td class="text"><input name ="type[]" type="hidden" value<?php echo $TYPE;?>></td>
    </tr>

    <?php
    $LINE
    ++;
    $rowclass $rowclass;
    }
    ?>

    <tr>
    <td><br/><input name="submit" type="submit" value="Submit"></td>
    </tr>
    </form>
    </table>
     
     <?php
     
    if (is_array($_POST['checkbox'])) {
    $ohord $_POST['ohord'];
    $ohbord $_POST['ohbord'];

     foreach(
    $_POST['checkbox'] as $line_no){
        
    $selstring "INSERT INTO LPCUSTTST.OPPSHEDT(sheddat, shedtyp, shedord, shedbord) VALUES($DATE,'$TYPE', '$ohord[$line_no]','$ohbord[$line_no]')";
        echo 
    $selstring;
        
    $s $db->prepare("$selstring"); 
        
    $s->execute();}
    }    
    ?>
     <?php
     
    //include("footer.php");
     
    ?>
     
    </body>
    </html>

  • #2
    Re: PHP Newbie needs help with checkbox selection program

    Just a quick note.. You have the same name for all of the check boxes, they all need to have separate names otherwise how do you know which one was selected. You say it wont get past the first section? what errors are being logged?

    Chris...

    Comment


    • #3
      Re: PHP Newbie needs help with checkbox selection program

      Once I press submit after I have selected the checkbox I am getting the error.
      The $date and the $type are not getting passed back to the top of the program.
      When the screen initially loads they have values from the first screen. Now the value says ARRAY
      The error is on the SQL below because it is selecting out by these fields.
      PHP Code:
      echo "date is " $date;
      echo 
      "type is " $type;
      // Insert data into header if does not already exist if it does exist update Manpower. 
      $selstring "Select Count(*) From LPCUSTTST.OPPSHEHD where shehdat = $date and shehtyp = '$type'";
      $s $db->prepare("$selstring"); 
      $s->execute() 
      This is the error I have the echo before the SQL and the fields are saying the values are ARRAY now.

      date is Arraytype is Array
      PHP Code:
      ( ! ) Fatal errorUncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 0 [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0206 - Column ARRAY not in specified tables. (SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)' in C:\wamp\www\LIID\DSH\apps\ShipEstimate.php on line 60
      ( ! ) PDOExceptionSQLSTATE[42S22]: Column not found[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0206 Column ARRAY not in specified tables. (SQLPrepare[0at ext\pdo_odbc\odbc_driver.c:206in C:\wamp\www\LIID\DSH\apps\ShipEstimate.php on line 60 
      Call Stack
      # Time Memory Function Location
      1 0.0000 411736 {main}( ) ..\ShipEstimate.php:0
      2 0.1560 414736 prepare ( ) ..\ShipEstimate.php:60

      Sorry about not knowing what I'm doing. I got thrown into this project because I took a PHP class about 4 years ago. I am the only one here that knows at least very little about PHP besides the manager that set up the WAMP.

      I'm wondering if I need the form to call a new program to do the detail updates instead of it calling target='_self'.
      I also thought by putting the checkbox in an array it would differentiate the checkboxes.
      If someone could tell me how to write this I really would appreciate it.
      I've done mostly one screen display programs and this is really more complicated than I have done before.
      Thanks,
      Mary Beth
      Last edited by jamief; July 17th, 2014, 06:03 AM.

      Comment


      • #4
        Re: PHP Newbie needs help with checkbox selection program

        The SQl string may not be as you think?

        $selstring = "Select Count(*) From LPCUSTTST.OPPSHEHD where shehdat = $date and shehtyp = '$type'"; I would normally code this as

        $selstring = "Select Count(*) From LPCUSTTST.OPPSHEHD where shehdat =" . $date ." and shehtyp = " .$type;

        You could use the single mark options as well but I find this always makes it easier to read.,

        Also the following $s = $db->prepare("$selstring"); should be $s = $db->prepare($selstring); you would otherwise be passing in "$selstring" which is a string not a variable.

        Chris..

        Comment

        Working...
        X