Topic: Checkboxes, PHP & MySQL
I need to allow (or not) a post. I can´t figure out how to get the value of the checkbox through an array, and UPDATE the DB with it.
Thanks in advance.
<form action="<?php echo ($PHP_SELF); ?>" method="post" class="font">
<table width="90%" border="1" align="center">
<tr>
<?php
require '../config.php';
$dbs = $dbs['estariabueno'];
$dbh=mysql_connect ("$db_host", "$db_username", "$db_password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$db_name");
$query="SELECT * FROM $dbs ORDER BY id";
$result = mysql_query($query);
$num = mysql_numrows($result);
$query = "INSERT INTO $dbs VALUES ($id,'$titulo','$texto','$fuente','$fecha')";
mysql_query($query);
$result = mysql_query("SELECT * FROM $dbs");
$num_rows = mysql_num_rows($result);
mysql_close();
?>
<tr>
<td><b>NAME</b></td>
<td><b>TEXT</b></td>
<td><b>DATE</b></td>
<td><b>IP</b></td>
<td><b>ALLOW</b></td>
<td><b>EDIT / DEL</b></td></tr>
<?
$i = 0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$text=mysql_result($result,$i,"text");
$name=mysql_result($result,$i,"name");
$allow = array(
"IDAllow" => $id,
"Valor" => mysql_result($result,$i,"allow")
);
$fecha=mysql_result($result,$i,"fecha");
$ip=mysql_result($result,$i,"ip");
?>
<td><strong><? echo $name; ?></strong></td>
<td><div align="justify"><? echo $text; ?></div><br></td>
<td><div align="center"><? echo $fecha; ?></div><br></td>
<td><div align="center"><? echo $ip; ?></div><br></td>
<?php
if ($allow[Valor] == "yes")
{
$printChecked = "checked='checked'";
} else {
$printChecked = "";
}
?>
<td><input type="checkbox" name="reg[]" value="reg[<?php echo $id; ?>]" <? echo $printChecked; ?>/></td>
<?php
echo "<td><a href='editar.php?cmd=edit&id=$id'>Editar</a><br><a href='eliminar.php?cmd=delete&id=$id'>Eliminar</a></td></tr>";
$i++;
}
?>
</tr></table>
</td>
</tr>
</table>
<input name="submit" type="submit" value="submit" />
</form>
<?
if ($_POST["$submit"])
{
// ?????????????????????
}
?>