I've having very much trouble with the last piece of my site. I retrieve my database including checkboxes.
From here I want to check/ucheck the boxes and save it back into the database.
The problem I run into is when I check some boxes it doesnt take any notice witch 'id' it is. When I check the last two boxes it will fill the first two.
Here is my code {Please help!!!!!}:
<?php require_once('Connections/Webw.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
// $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "status")) {
for($i=0;$i<count($_POST["id"]);$i++){
$updateSQL = sprintf("UPDATE aangekocht SET voldaan=%s, afgestuurd=%s WHERE id=%s",
GetSQLValueString($_POST['betaald'][$i], "text"),
GetSQLValueString($_POST['verstuurd'][$i], "text"),
GetSQLValueString($_POST['id'][$i], "int"));
mysql_select_db($database_webw, $webw);
$Result1 = mysql_query($updateSQL, $webw) or die(mysql_error());
}
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_webw, $webw);
$query_Recordset1 = "SELECT * FROM aangekocht";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $webw) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<form action="<?php echo $editFormAction; ?>" method="POST" name="status">
<table width="400" border="1">
<tr>
<td><?php echo $_POST['betaald']; ?></td>
<td><?php echo $_POST['verstuurd']; ?></td>
<td><?php echo $_POST['id']; ?></td>
<td><?php $i = count($_POST["betaald"]); echo $i?></td>
<td> </td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['klantnummer']; ?></td>
<td><?php echo $row_Recordset1['productnummer']; ?></td>
<td><?php echo $row_Recordset1['aantal']; ?></td>
<td><input <?php if (!(strcmp($row_Recordset1['voldaan'],1))) {echo "checked=\"checked\"";} ?> name="betaald[]" type="checkbox" value="1" /></td>
<td><input <?php if (!(strcmp($row_Recordset1['afgestuurd'],1))) {echo "checked=\"checked\"";} ?> name="verstuurd[]" type="checkbox" value="1" />
<input name="id[]" type="hidden" value="<?php echo $row_Recordset1['id']; ?>" /></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p align="justify"><a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
|||
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a></p>
<br />
<input name="update" type="submit" value="update" />
<input type="hidden" name="MM_update" value="status" />
</form>
<?php mysql_free_result($Recordset1);
?>
thanks for any reaction.