update statement doesn't do anything to my table
I get no errors and all my print statements are telling me i'm doing a good job, yet my field under the desired column stay the same.
what is happening (or rather not happening)?
if ($current && $new) {// the validation code is left out
$sqlTekst = "UPDATE gebruikers SET pasW = ". $_POST[nieuwPasw] ." WHERE gebruikersNr = ". $_POST[gebruikersNr];
print 'huidig POST gebruikersNr = $_POST[gebruikersNr]';
// server koppeling
$db = mysql_connect("localhost", "internet", "geheim");
// database koppeling
mysql_select_db("site_met_aanmelden", $db)
开发者_如何学Go or die("Kan database gebruikers niet openen".mysql_error());
$resultaat = mysql_query($sqlTekst, $db);
}
Did you 'commit' the database changes?
add error handling for the actual query execution
take care of possible sql injections
check affected rows to see whether your WHERE-condition works or not
format and indent your sql statement and you'll get a slightly more meaningful error message
print your sql statement so you can check all of the parameters
use $array['string'] instead of $array[string]
if ($current && $new) { // the validation code is left out
$db = mysql_connect("localhost", "internet", "geheim") or die("connect failed. ".mysql_error());
mysql_select_db("site_met_aanmelden", $db) or die("Kan database gebruikers niet openen".mysql_error());
$sql_pasW = mysql_real_escape_string($_POST['nieuwPasw'], $db);
$sql_gebruikersNr = mysql_real_escape_string($_POST['gebruikersNr'], $db);
$sqlTekst = sprintf("
UPDATE
gebruikers
SET
pasW='%s'
WHERE
gebruikersNr ='%s'
", $sql_pasW, $sql_gebruikersNr
);
echo 'Debug '.__FILE__.__LINE__.': ', $sqlTekst, "\n";
$resultaat = mysql_query($sqlTekst, $db) or die('query failed: '.mysql_error());
echo 'affected rows: ', mysql_affected_rows($db);
}
I would fix it as follows:
$sqlTekst = "UPDATE gebruikers SET pasW = '". $_POST["nieuwPasw"] ."' WHERE gebruikersNr = ". $_POST["gebruikersNr"];
Assuming your Nr
refers to number which doesn't need quotes in the select.
I assume at least of your $_POST['nieuwPasw']
or $_POST['gebruikersNr']
is string and you don't enclose it with ' in your query.
Your working query would be
$sqlTekst = "UPDATE gebruikers SET pasW = '". $_POST['nieuwPasw'] ."' WHERE gebruikersNr = '". $_POST['gebruikersNr']."'";
Just replace a string.
you can also get information if there error emerged in your query by using mysql_error function.
Add
if (!$resultaat) {
echo mysql_error();
}
this would print error occured during query.
I'd also suggest to enclose arrays keys in apostrophs (double or singular - does not really matter).
Try it like that:
$sqlTekst = "UPDATE gebruikers SET pasW = '". $_POST[nieuwPasw] ."' WHERE gebruikersNr = '". $_POST[gebruikersNr]."'";
精彩评论