Jump to content

Warning: Invalid argument supplied for foreach() in /home2/time/public_html/ipha


subash85

Recommended Posts

the code dispplay the products name with the supplied mysql data and even print the textbox each for data. with opening stock,closing stock, stock receive, extra adjusment.. now i need to do is that.. post all the data from data field to my mysql table i used foreach() but i got problem. like "Warning: Invalid argument supplied for foreach() in /home2/time/public_html/ipharma/add-stock.php on line 9 "

can anyone help me out...?

----------------------------------------

form.php

-----------------------------------------

<form name="stockiest" method="post"  action="add-stock.php" onsubmit="return valid_form()">
<table width="100%" border="0" align="center" cellpadding="5">
<tr>
  <td align="center" bgcolor="#FFFFFF"> <table border="0" align="center" cellpadding="2" cellspacing="2" bordercolor="#eeeeee" frame="hsides">
      <tr class="poll">
       <td colspan="10" bgcolor="#E0E0E0"><table width="100%" cellpadding="2" cellspacing="1">
    <tr>
      <td width="100" bgcolor="#CCCCCC"> Stockiest Name: </td>
      <td width="386" bgcolor="#CCCCCC">
  <?php
		$query="SELECT stockiest_name, stockiest_add FROM stockiest where stockiest_hq='$login_headq' and stockiest_div='$title_div'";
	  	$result = mysql_query($query);
	  	echo '<select name="stockiest_name_stock">';
		echo '<option>Select Type</option>';
  			while ($row = mysql_fetch_assoc($result))
		{
		echo '<option value="' . $row['stockiest_name'] . '">' . $row['stockiest_name'] . ', '. $row['stockiest_add'].'</option>';
		}
		echo '</select>'; 
				  
				  
?> 
</td>
      <td bgcolor="#CCCCCC">Month :
  <select name="month">
  <option>Select Month</option>
  <option> Srawan </option>
          <option value="Bhadra "> Bhadra </option>
          <option value="Ashwin"> Ashwin </option>
          <option value="Kartik"> Kartik </option>
          <option value="Mangsir"> Mangsir </option>
          <option value="Poush"> Poush </option>
          <option value="Magh"> Magh </option>
          <option value="Falgun"> Falgun </option>
          <option value="Chaitra"> Chaitra </option>
          <option value="Baishak"> Baishak </option>
          <option value="Jestha"> Jestha </option>
          <option value="Ashar"> Ashar </option>
          </select></td>
       </tr>
    <tr>
      <td bgcolor="#CCCCCC">Headquater : </td>
      <td bgcolor="#CCCCCC" >
  <input type="hidden" name="headqr" value="<?php echo"$login_headq";?>" />
  <?php echo "<b>$login_headq</b>"?> || Division :<?php echo "<b> $title_div</b>"?>
  </td>
  
      <td width="204" bgcolor="#CCCCCC">Fiscal Year:
        <select name="fiscalyear">
          <option>Select Year</option>
          <option>2066/2067</option>
          </select></td>
      </tr>
    </table></td>
        </tr>
      <tr bgcolor="#abcae6" class="poll" style="font-weight:bold;">
        <td bgcolor="#CCCCCC"> SN </td>
        <td align="center" bgcolor="#CCCCCC">   PRODUCT NAME   </td>
        <td bgcolor="#CCCCCC"> CODE</td>
        <td bgcolor="#CCCCCC">PACKING</td>
        <td bgcolor="#CCCCCC">OPENING STOCK</td>
        <td bgcolor="#CCCCCC">STOCK RECEIVED</td>
        <td align="center" bgcolor="#CCCCCC">SALES</td>
        <td align="center" bgcolor="#CCCCCC">E.ADJUSTMENT</td>
        <td align="center" bgcolor="#CCCCCC">   CLOSING STOCK   </td>
        </tr>
      <?php
$f_user="select login_div from users where login_id='$re_user_id'";
$f_result=mysql_query($f_user);
while ($a_row=mysql_fetch_array($f_result))
{
	$f_usr_div=$a_row['login_div'];
}
?>
      <?php
		$i = 0;
		$query1="select division, pname, pcode, ptype, unit, packing, division from products where division='$f_usr_div' ORDER BY pname";
		$result1=mysql_query($query1);
		$i=0;
		while ($a_row=mysql_fetch_array($result1))
			{
				global $i;
				$i++;
				$db_id=$a_row['id'];
				$db_pname=$a_row['pname'];
				$db_pcode=$a_row['pcode'];
				$db_packing=$a_row['packing'];
				$db_type=$a_row['ptype'];
				$db_unit=$a_row['unit'];
				$db_remark=$a_row['remark'];
				$db_div=$a_row['division'];
				print "<tr>
			<td bgcolor=\"#F5F5F5\">$i</td>
			<td bgcolor=\"#F5F5F5\">
			<input type=\"hidden\" value=\"$db_pname\" name=\"prname[$i]\">$db_pname ($db_type)</td>
			<td bgcolor=\"#F5F5F5\">
			<input type=\"hidden\" value=\"$db_pcode\" name=\"pcode[$i]\" >$db_pcode</td>
			<td bgcolor=\"#F5F5F5\">
			<input type=\"hidden\" value=\"$db_packing\" name=\"packing[$i]\" >$db_packing</td>
			<td bgcolor=\"#F5F5F5\" align=\"center\">
			<input type=\"text\" name=\"opening_stock[$i]\" size=\"5\" ONCHANGE=\"suminp()\" ></td>
			<td bgcolor=\"#F5F5F5\" align=\"center\">
			<input type=\"text\" name=\"stock_rec[$i]\" size=\"5\" ONCHANGE=\"suminp()\" ></td>
			<td bgcolor=\"#F5F5F5\" align=\"center\">
			<input type=\"text\" name=\"sales[$i]\" size=\"5\" ONCHANGE=\"suminp()\" ></td>
			<td bgcolor=\"#F5F5F5\" align=\"center\">
			<input type=\"text\" name=\"eadjus[$i]\"size=\"5\" ONCHANGE=\"suminp()\" ></td>	
			<td bgcolor=\"#F5F5F5\" align=\"center\">
			<input type=\"text\" name=\"close_st[$i]\" size=\"5\" DISABLED>
				</td>

				</tr>";
		}

		?>
    </table></td>
</tr>
</table>
<div style="padding:15px;" align="center"><input type="submit" name="SUBMIT" value="Post Your Form" style="border:#666 1px dotted; background:#CCC; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:10px;"></div>
</form>

 

-----------------------------

add-stock.php

--------------------------

 

<?php
include("../config.php");
include("../dbconnect.php");
?>
<title>Adding Stock and Sales</title>
<?php

$value= array();
foreach($data as $row)
{
$value[]= '("'.mysql_real_escape_string($row['stockiest_name_stock']).'", '.$row['month'].' , '.$row['fiscalyear'].' ,' .$row['headqr'].' , '.$row['division'].' , '.$row['prname'].' , '.$row['pcode'].' , '.$row['packing'].' , '.$row['opening_stock'].' , '.$row['stock_rec'].' , '.$row['sales'].' , '.$row['close_st'].' , '.$row['eadjus'].')';
}
if( !empty($values) ) {
     $query = "INSERT INTO stockiest (userid, username, headqtr, month, fiscal_year, stockiest_name, stockiest_add, stockiest_phn, product_name, pro_code, p_packing, stock_open, stock_received, m_sales, e_adjus, stock_close, user_div) VALUES "   . implode(',',$values);
     mysql_query($query);
}
?>

 

hope u all would help me out..

what I'm saying is there is no data in $data... so it is trying to do a foreach on an empty variable. Which fails

 


$res=mysql_query("SELECT * FROM table WHERE 1");
while($row=mysql_fetch_array($res)){

foreach($row as $key=>$val){

echo $key.' : '.$val.'<br />';

}

}

 

will work fine, but only because there is an array in $row.

 

dude.. i think u dun understand what i really mean i am trying to post all the loop textbox with data in mysql data base.. and i m trying to do with foreach() but am unable to do that. so fren i would like to request can anyone give me best example for posting the data in mysql within while loop... thanking you once again...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.