Re: Foreach and mydql_query problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/22/2013 04:39 AM, Karl-Arne Gjersøyen wrote:


Might I suggest that you place your include for ../../tilkobling.php at the very top of this page? It would save you from possibly including it twice.

// The acutual source code is below:
// ==============================================
if(!empty($_POST['antall_kolli'])){
     include('../../tilkobling.php');               ---  remove this line

         foreach($antall_kolli as $kolli){
         echo "$kolli<br>";

             //    echo $kolli. "<br>";
             $sql = "UPDATE transportdokument SET antall_kolli_stk =
'$kolli' WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'";
             mysql_query($sql,$tilkobling) or die(mysql_error());
      }

Your WHERE conditions are the same, that is why it is updating a single row. Where are $dagens_dato and $brukernavn being defined? As others have stated, you need to include a unique identifier in your query so your query updates a specific record.

}

// THE PHP/HTML Form below:
include('../../tilkobling.php');           ---  move this to the top of the script

     $sql = "SELECT * FROM transportdokument WHERE dato = '$dagens_dato' AND
signatur = '$brukernavn'";
     $resultat = mysql_query($sql, $tilkobling) or die(mysql_error());
     while($rad = mysql_fetch_array($resultat, MYSQL_ASSOC)){
         $valgt_lager = $rad['valgt_lager'];
         $un_nr = $rad['un_nr'];
         $sprengstofftype = $rad['sprengstofftype'];
         $varenavn = $rad['varenavn'];
         $varenr = $rad['varenr'];
         $antall_kolli = $rad['antall_kolli_stk'];
         $adr_vekt_kg = $rad['adr_vekt_kg'];
         $varenavn = $rad['varenavn'];
         $emb = $rad['emb'];
?>
<tr>
     <td align="left" valign="top"><?php echo "$un_nr"; ?></td>
     <td align="left" valign="top"><strong>Sprengstoff</strong>,<?php echo
"$sprengstofftype"; ?></td>
     <td align="left" valign="top"><?php echo "$varenavn"; ?></td>
     <td align="left" valign="top"><strong>1.1D</strong></td>
     <td align="left" valign="top">&nbsp;</td>
     <td align="left" valign="top"><?php echo "$emb"; ?></td>
     <td align="left" valign="top">
     <input type="hidden" name="varenr[]" value="<?php echo "$varenr"; ?>">
     <input type="number" name="antall_kolli[]" size="6" value="<?php echo
"$antall_kolli"; ?>" required="required">
     </td>
     <td align="left" valign="top"><input type="text" name="exan_kg_ut[]"
size="6" value="<?php echo "$adr_vekt_kg"; ?>" required="required"></td>
</tr>
<?php
$total_mengde_kg_adr += $rad['adr_vekt_kg'];
$total_antall_kolli += $rad['antall_kolli_stk'];
     }

?>


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux