accessxtreme
November 27th, 2004, 10:54 PM
All,
After doing some heavy research and coding I am stuck on this one minor problem. What I am trying to do is take a mysql db to fill a checkbox. then those checkboxes can be checked so that users can select multiple items to get more information about. However, with the codes that I have tried it only returns the last value in the db table. Here is what I have for my form:
<?
include("header.php");
$table2 = "categories";
$sql2 = "SELECT id, cat_name, cat_sdescrip, cat_ldescrip FROM $table2";
$result2 = @mysql_query($sql2,$connection) or die(mysql_error());
$check_cat = "
<div>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Request Information About</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"><tr><td>";
while ($row2 = mysql_fetch_array($result2)) {
$id = $row2['id'];
$cat_name = $row2['cat_name'];
$check_cat .= "<input type=\"checkbox\" name=\"product\" value=$id>$cat_name<br>";
}
$check_cat .="</table></div>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Send Request\" name=\"submit\">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table></form>";
$display_form = "
<form method=\"post\" action=\"send_request.php\">
<div align=\"center\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Company/Contact Information</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong>Company Name:</strong></td>
<td><input type=\"text\" name=\"comp_name\" size=30></td>
</tr>
<tr>
<td><strong>Title:</strong></td>
<td><input type=\"text\" name=\"title\" size=30></td>
</tr>
<tr>
<td><strong>First Name:</strong></td>
<td><input type=\"text\" name=\"fname\" size=30></td>
</tr>
<tr>
<td><strong>MI:</strong></td>
<td><input type=\"text\" name=\"mi\" size=30 maxlength=1></td>
</tr>
<tr>
<td><strong>Last Name:</strong></td>
<td><input type=\"text\" name=\"lname\" size=30></td>
</tr>
<tr>
<td><strong>Address 1:</strong></td>
<td><input type=\'text\" name=\"address1\" size=30></td>
</tr>
<tr>
<td><strong>Address 2:</strong></td>
<td><input type=\'text\" name=\"address2\" size=30></td>
</tr>
<tr>
<td><strong>City:</strong></td>
<td><input type=\'text\" name=\"city\" size=30></td>
</tr>
<tr>
<td><strong>State:</strong></td>
<td><input type=\"text\" name=\"state\" size=30 maxlength=2></td>
</tr>
<tr>
<td><strong>Zip Code:</strong></td>
<td><input type=\"text\" name=\"zip\" size=30 maxlength=5></td>
</tr>
<tr>
<td><strong>E-Mail:</strong></td>
<td><input type=\'text\" name=\"email\" size=30></td>
</tr>
<tr>
<td><strong>Confirm E-Mail:</strong></td>
<td><input type=\"text\" name=\"email2\" size=30></td>
</tr>
<tr>
<td><strong>Phone:</strong></td>
<td><input type=\'text\" name=\"phone\" size=30></td>
</tr>
</table></div>
</td>
</tr>
</table>
<p>
$check_cat
</td>
</tr>
</table>
</td>
</tr>
</table>";
?>
And here is the information on send_request.php;
<?
if ((!$_POST[fname]) || (!$_POST[lname]) || (!$_POST[email]) || (!$_POST[phone])) {
header("Location: request.php");
} else {
include("header.php");
$display_form = "
<div align=\"center\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Company/Contact Information</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">";
if ($_POST[comp_name] != "") {
$display_form .="
<tr>
<td><strong>Company Name:</strong></td>
<td>$_POST[comp_name]</td>
</tr>";
}
if ($_POST[title] != "") {
$display_form .="
<tr>
<td><strong>Title:</strong></td>
<td>$_POST[title]</td>
</tr>";
}
if ($_POST[fname] != "") {
$display_form .="
<tr>
<td><strong>First Name:</strong></td>
<td>$_POST[fname]</td>
</tr>";
}
if ($_POST[mi] != "") {
$display_form .= "
<tr>
<td><strong>MI:</strong></td>
<td>$_POST[mi]</td>
</tr>";
}
if ($_POST[lname] != "") {
$display_form .= "
<tr>
<td><strong>Last Name:</strong></td>
<td>$_POST[lname]</td>
</tr>";
}
if ($_POST[address1] != "") {
$display_form .= "
<tr>
<td><strong>Address 1:</strong></td>
<td>$_POST[address1]</td>
</tr>";
}
if ($_POST[address2] != "") {
$display_form .= "
<tr>
<td><strong>Address 2:</strong></td>
<td>$_POST[address2]</td>
</tr>";
}
if ($_POST[city] != "") {
$display_form .= "
<tr>
<td><strong>City:</strong></td>
<td>$_POST[city]</td>
</tr>";
}
if ($_POST[state] != "") {
$display_form .= "
<tr>
<td><strong>State:</strong></td>
<td>$_POST[state]</td>
</tr>";
}
if ($_POST[zip] != "") {
$display_form .= "
<tr>
<td><strong>Zip Code:</strong></td>
<td>$_POST[zip]</td>
</tr>";
}
if ($_POST[email] != "") {
$display_form .= "
<tr>
<td><strong>E-Mail:</strong></td>
<td>$_POST[email]</td>
</tr>";
}
if ($_POST[phone] != "") {
$display_form .= "
<tr>
<td><strong>Phone:</strong></td>
<td>$_POST[phone]</td>
</tr>";
}
$display_form .= "
</table></div>
</td>
</tr>
</table>
<p>";
$display_cat = "
<div>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Requested Information About</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"><tr><td><ul type=\"1\">";
$table2 = "categories";
$sql2 = "SELECT id, cat_name, cat_sdescrip, cat_ldescrip FROM $table2 WHERE id = '$_POST[product]'";
$result2 = @mysql_query($sql2,$connection) or die(mysql_error());
$num = mysql_num_rows($result2);
if ($num != 0) {
while ($row2 = mysql_fetch_array($result2)) {
$id = $row2['id'];
$cat_name = $row2['cat_name'];
$cat_sdescrip = $row2['cat_sdescrip'];
$display_cat .= "<li>$cat_name<p><div style=\"padding-left:10px\">$cat_sdescrip";
}
}
$display_cat .="
</ul></table></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>";
$display_form .= "
$display_cat
</td>
</tr>
</table>
</td>
</tr>
</table>";
}
?>
Any help would be greatly appreciated. I was thinking about possibly using an array but not sure if there is an easier way of doing this. I am sure that in my send_request.php I can just say this
$sql = "SELECT * FROM $table_name WHERE id = '$_POST[product]' as product[]";
Or something of that nature. i am still trying a lot of stuff so I am going to see the results here shortly. thanks for any help.
jason
After doing some heavy research and coding I am stuck on this one minor problem. What I am trying to do is take a mysql db to fill a checkbox. then those checkboxes can be checked so that users can select multiple items to get more information about. However, with the codes that I have tried it only returns the last value in the db table. Here is what I have for my form:
<?
include("header.php");
$table2 = "categories";
$sql2 = "SELECT id, cat_name, cat_sdescrip, cat_ldescrip FROM $table2";
$result2 = @mysql_query($sql2,$connection) or die(mysql_error());
$check_cat = "
<div>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Request Information About</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"><tr><td>";
while ($row2 = mysql_fetch_array($result2)) {
$id = $row2['id'];
$cat_name = $row2['cat_name'];
$check_cat .= "<input type=\"checkbox\" name=\"product\" value=$id>$cat_name<br>";
}
$check_cat .="</table></div>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Send Request\" name=\"submit\">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table></form>";
$display_form = "
<form method=\"post\" action=\"send_request.php\">
<div align=\"center\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Company/Contact Information</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong>Company Name:</strong></td>
<td><input type=\"text\" name=\"comp_name\" size=30></td>
</tr>
<tr>
<td><strong>Title:</strong></td>
<td><input type=\"text\" name=\"title\" size=30></td>
</tr>
<tr>
<td><strong>First Name:</strong></td>
<td><input type=\"text\" name=\"fname\" size=30></td>
</tr>
<tr>
<td><strong>MI:</strong></td>
<td><input type=\"text\" name=\"mi\" size=30 maxlength=1></td>
</tr>
<tr>
<td><strong>Last Name:</strong></td>
<td><input type=\"text\" name=\"lname\" size=30></td>
</tr>
<tr>
<td><strong>Address 1:</strong></td>
<td><input type=\'text\" name=\"address1\" size=30></td>
</tr>
<tr>
<td><strong>Address 2:</strong></td>
<td><input type=\'text\" name=\"address2\" size=30></td>
</tr>
<tr>
<td><strong>City:</strong></td>
<td><input type=\'text\" name=\"city\" size=30></td>
</tr>
<tr>
<td><strong>State:</strong></td>
<td><input type=\"text\" name=\"state\" size=30 maxlength=2></td>
</tr>
<tr>
<td><strong>Zip Code:</strong></td>
<td><input type=\"text\" name=\"zip\" size=30 maxlength=5></td>
</tr>
<tr>
<td><strong>E-Mail:</strong></td>
<td><input type=\'text\" name=\"email\" size=30></td>
</tr>
<tr>
<td><strong>Confirm E-Mail:</strong></td>
<td><input type=\"text\" name=\"email2\" size=30></td>
</tr>
<tr>
<td><strong>Phone:</strong></td>
<td><input type=\'text\" name=\"phone\" size=30></td>
</tr>
</table></div>
</td>
</tr>
</table>
<p>
$check_cat
</td>
</tr>
</table>
</td>
</tr>
</table>";
?>
And here is the information on send_request.php;
<?
if ((!$_POST[fname]) || (!$_POST[lname]) || (!$_POST[email]) || (!$_POST[phone])) {
header("Location: request.php");
} else {
include("header.php");
$display_form = "
<div align=\"center\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Company/Contact Information</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">";
if ($_POST[comp_name] != "") {
$display_form .="
<tr>
<td><strong>Company Name:</strong></td>
<td>$_POST[comp_name]</td>
</tr>";
}
if ($_POST[title] != "") {
$display_form .="
<tr>
<td><strong>Title:</strong></td>
<td>$_POST[title]</td>
</tr>";
}
if ($_POST[fname] != "") {
$display_form .="
<tr>
<td><strong>First Name:</strong></td>
<td>$_POST[fname]</td>
</tr>";
}
if ($_POST[mi] != "") {
$display_form .= "
<tr>
<td><strong>MI:</strong></td>
<td>$_POST[mi]</td>
</tr>";
}
if ($_POST[lname] != "") {
$display_form .= "
<tr>
<td><strong>Last Name:</strong></td>
<td>$_POST[lname]</td>
</tr>";
}
if ($_POST[address1] != "") {
$display_form .= "
<tr>
<td><strong>Address 1:</strong></td>
<td>$_POST[address1]</td>
</tr>";
}
if ($_POST[address2] != "") {
$display_form .= "
<tr>
<td><strong>Address 2:</strong></td>
<td>$_POST[address2]</td>
</tr>";
}
if ($_POST[city] != "") {
$display_form .= "
<tr>
<td><strong>City:</strong></td>
<td>$_POST[city]</td>
</tr>";
}
if ($_POST[state] != "") {
$display_form .= "
<tr>
<td><strong>State:</strong></td>
<td>$_POST[state]</td>
</tr>";
}
if ($_POST[zip] != "") {
$display_form .= "
<tr>
<td><strong>Zip Code:</strong></td>
<td>$_POST[zip]</td>
</tr>";
}
if ($_POST[email] != "") {
$display_form .= "
<tr>
<td><strong>E-Mail:</strong></td>
<td>$_POST[email]</td>
</tr>";
}
if ($_POST[phone] != "") {
$display_form .= "
<tr>
<td><strong>Phone:</strong></td>
<td>$_POST[phone]</td>
</tr>";
}
$display_form .= "
</table></div>
</td>
</tr>
</table>
<p>";
$display_cat = "
<div>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"images/fon01.jpg\">
<tr>
<td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
<tr>
<td><strong class=\"orangetext\">Requested Information About</strong></td>
</tr>
</table>
<p>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><div style=\"padding-left:25px\">
<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"><tr><td><ul type=\"1\">";
$table2 = "categories";
$sql2 = "SELECT id, cat_name, cat_sdescrip, cat_ldescrip FROM $table2 WHERE id = '$_POST[product]'";
$result2 = @mysql_query($sql2,$connection) or die(mysql_error());
$num = mysql_num_rows($result2);
if ($num != 0) {
while ($row2 = mysql_fetch_array($result2)) {
$id = $row2['id'];
$cat_name = $row2['cat_name'];
$cat_sdescrip = $row2['cat_sdescrip'];
$display_cat .= "<li>$cat_name<p><div style=\"padding-left:10px\">$cat_sdescrip";
}
}
$display_cat .="
</ul></table></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>";
$display_form .= "
$display_cat
</td>
</tr>
</table>
</td>
</tr>
</table>";
}
?>
Any help would be greatly appreciated. I was thinking about possibly using an array but not sure if there is an easier way of doing this. I am sure that in my send_request.php I can just say this
$sql = "SELECT * FROM $table_name WHERE id = '$_POST[product]' as product[]";
Or something of that nature. i am still trying a lot of stuff so I am going to see the results here shortly. thanks for any help.
jason