Forum Moderators: coopster
<?php
include("dbconnect.php");
if ($update){
$sql = "UPDATE sponsor SET sp_show = '".$row["sp_show"]."' WHERE sponsor_id=$sponsor_id";
$resultaat = mysql_query($sql);
header("Location: sponsor_view.php");
}
$result = mysql_query("SELECT * FROM sponsor ORDER BY sponsor_id desc");
if ($result)
echo "<br><form method=post action=sponsor_view.php><table align=center cellspacing=0 border=0 width=95%><tr><td colspan=5 align=center><h3>sponsor - Seniors</h3>";
{
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align=left width=10>";
echo "<a href=\"sponsor_delete.php?sponsor_id=".$row["sponsor_id"]."\"><img src=../images/ed_delete_red.gif border=0 alt=delete></a>";
echo "<td align=left width=100>";
?>
<input type="checkbox" name="sp_show" <?php if($row["sp_show"] == "ja"){echo "CHECKED";}?>> visible
<?php
echo "</td>";
echo "<td align=left width=300><b>";
echo $row["sp_name"];
echo "</b></td><td>";
echo $row["sp_type"];
echo "</td></tr>";
}
echo "<tr><td colspan=4><input type=submit value=save name=update></td></tr>";
echo "</form></table>";
}
?>
This should someone give the possibility to set the visibility of a sponsor on the real site on true, just by toggling the sp_show row with the checkboxes. But this doesn't work. Does someone have a suggestion
By the way sp_show is a ENUM field with values of YES & NO
Thnx, Greetings Raśl
One important thing to remember with checkboxes is that their values are not available to PHP until they are ticked, and the form submitted. This usually means that you need to know the name of the checkbox before you can test for it's existence, and then value:
This is just an example of processing multiple checkboxes, hopefully you can make something similar work in your own code:
[/quote]
<?php
if (isset($_POST['update']))
{
$numberOfCheckboxes = 4;
for ($i = 1; $i <= $numberOfCheckboxes; $i ++)
{
if (isset($_POST['checkbox_' . $i]))
{
// you can build something for your update query in here
}
}
}
?>
<!-- example checkbox html -->
<form name="whatever" action="sponsor_view.php" method="post">
<input name="checkbox_1" value="yes" type="checkbox" />
<input name="checkbox_2" value="yes" type="checkbox" />
<input name="checkbox_3" value="yes" type="checkbox" />
<input name="checkbox_4" value="yes" type="checkbox" />
<input type="submit" value="save" name="update">
</form>
[quote]