abs0lut Posted August 20, 2008 Share Posted August 20, 2008 Warning: Invalid argument supplied for foreach() in ... <?php session_start(); include 'conn.php'; $post = $_GET['post']; if(isset($_POST['checkb'])){ if(count($_POST['$iqid']) > 0){ foreach($_POST['$iqid'] as $awr) { $result = mysql_query("UPDATE ctable SET updated='yes' WHERE id='$awr'") or die(mysql_error()); } } } else{ ?> <form method="post" name="formk" action="<?= $_SERVER['PHP_SELF']. '?' . $_SERVER['QUERY_STRING'] ?>"> <?php $result = mysql_query("SELECT cid, iqid, cost, usersid FROM ctable WHERE post=$post"); while ($row = mysql_fetch_array($result)) { $arr[$row['iqid']][$row['usersid']] = $row['cost']; $arr2[$row['iqid']][$row['usersid']] = $row['cid']; $uid[] = $row['usersid']; } $uid = array_unique($uid); $qid = array_keys($arr); echo '<table><tr><td></td>'; foreach($uid as $userid) echo "<td>$userid</td>"; echo '</tr>'; foreach($qid as $iqid) { echo "<tr><td>$iqid</td>"; foreach($uid as $userid) { if (isset($arr[$iqid][$userid])) { echo "<td>".$arr[$iqid][$userid]."<input type='radio' name='$iqid' value='{$arr2[$iqid][$userid]}'></td>"; } else echo "<td></td>"; } echo "</tr>"; } echo '</table>'; echo '<input type="submit" name="checkb" />'; echo'</form>'; } ?> thanks, please check... Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/ Share on other sites More sharing options...
kenrbnsn Posted August 20, 2008 Share Posted August 20, 2008 What is the full error message? It tells you which line has the problem. Ken Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620642 Share on other sites More sharing options...
abs0lut Posted August 20, 2008 Author Share Posted August 20, 2008 Warning: Invalid argument supplied for foreach() in n /public_html/****/***** online 8 Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620671 Share on other sites More sharing options...
vbnullchar Posted August 20, 2008 Share Posted August 20, 2008 change your condition to this if(!empty($_POST['$iqid']) && count($_POST['$iqid']) > 0) Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620675 Share on other sites More sharing options...
.josh Posted August 20, 2008 Share Posted August 20, 2008 in your form, iqid is a radio button, so only 1 option will be selected, and $_POST['iqid'] will not be an array. Were you perhaps meaning to do name='iqid[]' and have checkboxes? Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620693 Share on other sites More sharing options...
abs0lut Posted August 20, 2008 Author Share Posted August 20, 2008 Crayon Violent, the name of the radio button is $iqid I don't want to use checkbox vbnullchar, don't I need to change foreach($_POST['$iqid'] as $awr) ?? could you please help me? Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620710 Share on other sites More sharing options...
vbnullchar Posted August 20, 2008 Share Posted August 20, 2008 Crayon Violent, the name of the radio button is $iqid I don't want to use checkbox vbnullchar, don't I need to change foreach($_POST['$iqid'] as $awr) ?? could you please help me? if $_POST['$iqid'] is an array just leave it that way.. just add an array check before that Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620721 Share on other sites More sharing options...
.josh Posted August 20, 2008 Share Posted August 20, 2008 okay...so you want a radio button. But that's the point. Your form has a bunch of radio buttons. Only one will be selected. So $_POST['iqid'] will never be an array. It will always be just a variable with one of those radio button values. Therefore, your foreach loop will never work. There's no point in even having your query inside a loop at all. You're getting a single value from your form and updating your database with that value. No foreach loop or any loop at all required. If you do what vbnullchar says, your query will never be executed because it will never be an array. Link to comment https://forums.phpfreaks.com/topic/120453-warning-invalid-argument-supplied-for-foreach-in/#findComment-620724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.