Witam.
Stworzyłem sobie formularz który wyświetla dane użytkowników. Chcę by po zmianie w polach i naciśnięciu wyslij aktualizował wszystkie rekordy. Jak na razie aktualizuje ostatni rekord. Myślę że błąd robię w zapytaniu update. Prosze o pomoc.
<?php require_once('../Connections/myconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); }
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE admin SET name=%s, email=%s WHERE id=%s", GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['id'], "int"));
$updateGoTo = "reba.php";
if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ?
"&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING'];
}
}
$query_Recordset1 = "SELECT * FROM `admin`";
?>
<form name="form1" method="POST" action="
<?php echo $editFormAction; ?>">
<p> </p>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php do { ?>
<tr>
<td><label for="id"></label>
<input name="id" type="text" id="id" value="
<?php echo $row_Recordset1['id']; ?>" size="15" maxlength="15"></td>
<td><label for="name"></label>
<input name="name" type="text" id="name" value="
<?php echo $row_Recordset1['name']; ?>" size="15" maxlength="15"></td>
<td><label for="email"></label>
<input name="email" type="text" id="email" value="
<?php echo $row_Recordset1['email']; ?>" size="15" maxlength="15"></td>
</tr>
<input name="id" type="hidden" id="id" value="
<?php echo $row_Recordset1['id']; ?>">
</table>
<p>
<input type="submit" name="button" id="button" value="Wyślij">
</p>
<p> </p>
<input type="hidden" name="MM_update" value="form1">
</form>
<?php
?>
Ten post edytował woxala123 14.08.2013, 09:33:14