subash85 Posted August 17, 2009 Share Posted August 17, 2009 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.. Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/ Share on other sites More sharing options...
seventheyejosh Posted August 17, 2009 Share Posted August 17, 2009 " foreach($data as $row) " what gets put in $data? anything? ... Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/#findComment-900019 Share on other sites More sharing options...
subash85 Posted August 18, 2009 Author Share Posted August 18, 2009 as if i would like to get the data from that form as rows and post it in to mysql but i am unable....so em asking for help that am i wrong in script code or other.. so ppl Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/#findComment-900653 Share on other sites More sharing options...
seventheyejosh Posted August 18, 2009 Share Posted August 18, 2009 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. Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/#findComment-900680 Share on other sites More sharing options...
subash85 Posted August 19, 2009 Author Share Posted August 19, 2009 thanks i will post does it work on not tomrrow.? thank you dude. Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/#findComment-901542 Share on other sites More sharing options...
pudge1 Posted August 19, 2009 Share Posted August 19, 2009 $data is not set I think you are meaning to set $value the array set above it. Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/#findComment-901556 Share on other sites More sharing options...
subash85 Posted August 19, 2009 Author Share Posted August 19, 2009 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... Link to comment https://forums.phpfreaks.com/topic/170630-warning-invalid-argument-supplied-for-foreach-in-home2timepublic_htmlipha/#findComment-901718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.