Form Input variable into array - Please help
Posted: Mon Jan 05, 2009 12:34 pm
Hi I have been struggling with this code for a while now and I cant get it to work. I am kind of new to php and I have been trying to figure it out searching the web and trial and error. I am trying to display some records from my db into a table and one of the fields (exchmemberid) I want to be able to input it into an array. When I try to read it with foreach loop I get an error "Warning: Invalid argument supplied for foreach()" I guess it is because I am not setting up the array correctly and it is trying to read an array but it is not finding an array????
I am posing my code to see if someone could please tell me what is wrong.
Thanks in advance..
I am posing my code to see if someone could please tell me what is wrong.
Thanks in advance..
Code: Select all
<?php
require_once ("config.php");
$q1 = "SELECT * FROM exchanges ORDER BY exch_id";
$r1 = mysql_query($q1) or die(mysql_error());
$siterefid = $_SESSION['siterefid'];
$q2 = "SELECT * FROM users_exchg WHERE site_ref_id = $siterefid ORDER BY exch_id";
$r2 = mysql_query($q2) or die(mysql_error());
mysql_close();
$output = "<form method='post' action='saveform.php'>";
$output .= "<table cellSpacing='0' cellPadding='4' width='1046' border='1' bordercolorlight='#CE5A5A' bordercolordark='#CE5A5A' style='border-collapse: collapse' bordercolor='#111111' align='center'>\n";
$output .= "<tr>\n";
$output .= "<td class='cell5' bgcolor='#CE5A5A'>\n";
$output .= "<font size='2' color='#FFFFFF' face='Arial'><b>Category</b></font></td>\n";
$output .= "<td class='cell5' bgcolor='#CE5A5A'>\n";
$output .= "<b><font face='Arial' size='2' color='#FFFFFF'>Company Name</font></b></td>\n";
$output .= "<td class='cell4' bgcolor='#CE5A5A'>\n";
$output .= "<font size='2' color='#FFFFFF' face='Arial'><b>Description</b></font></td>\n";
$output .= "<td class='cell4' align='middle' bgcolor='#CE5A5A'>\n";
$output .= "<b><font face='Arial' size='2' color='#FFFFFF'>Ref. Link</font></b></td>\n";
$output .= "<td class='cell4' align='middle' bgcolor='#CE5A5A'>\n";
$output .= "<b><font face='Arial' size='2' color='#FFFFFF'>Ref. ID</font></b></td>\n";
while($a1 = mysql_fetch_array($r1))
{
$a2 = mysql_fetch_array($r2);
$exchmemberid = $a2[exch_member_id];
$a3 = array(exchmemberid);
IF (strlen($a2[exch_member_id] <= 0)) {
$exchlinkid = $a2[exch_ref_by];
}
else {
$exchlinkid = $a2[exch_member_id];
}
$refurl = $a1['reflink'] . $exchlinkid;
$output .= "<tr onmouseover=\"this.bgColor='#FEF2CB';\" onmouseout=\"this.bgColor='#FFFFFF';\" bgColor=\"#ffffff\">\n";
$output .= "<td><font face='arial' size='2'>" . $a1["category"] . "</font></td>\n";
$output .= "<td><font face='arial' size='2'>" . $a1['coname'] . "</font></td>\n";
$output .= "<td><font face='arial' size='2'>" . $a1["description"] . "</font></td>\n";
$output .= "<td><font face='arial' size='2'>";
$output .= "<a href='$refurl' TARGET='_blank'>Sign Up Here</a></font></td>\n";
$output .= "<td><font face='arial' size='2'>";
$output .= "<input type='text' name='exchmemberid' value='$a3[exchmemberid]'></font></td>\n";
$output .= "</tr>\n";
}
$output .= "</table>\n";
$output .= "<input type='submit' value='Submit' name='submit' onSubmit='return check()'>";
$output .= "</form>\n";
$output .= "<br>\n";
$exchmemberid = $ad[exchmemberid];
?>
<table width='946' border="0" align="center" cellSpacing='0' cellPadding='4'>
<tr>
<td>
<font face="Arial, Verdana" size="5">
<b>Title goes here</b></font><br>
<br>
<font face="Arial, Verdana" size="2">
Description goes here....</font>
</td>
</tr>
<tr>
<td>
<?php echo $output ?>
</td>
</tr>
</table>
Code: Select all
******************saveform.php**********************************
<?php
require_once ("config.php");
$siterefid = $_SESSION['siterefid'];
$q1 = "SELECT * FROM users_exchg WHILE site_ref_id = $siterefid ORDER BY exch_id";";
$r1 = mysql_query($q1) or die(mysql_error());
mysql_close();
// list $a3 array values
$exchmemberid = $_SESSION[exchmemberid];
foreach ($exchmemberid as $exchmemberid_value) {
echo "Value: " . $exchmemberid_value . "<br />\n";
echo "Count: " . count($a3) . "<br />";
}
// UPDATE users_exchg SET exch_member_id = $exchmemberid";
?>