I’ve copied code from another topic on stackoverflow, but it isn’t working here.. Searched on the internet but couldn’t find anything about this simple thing, the query is not working.
I want to update a table.
Form:
<form method="post" action="klas_bewerken.php">
<label>Old</label> <input name="old" type="text" id="textfield" />
<label>New</label> <input name="new" type="text" id="textfield" />
<input type="submit" value="Change now" />
</form>
Klas_bewerken.php
<?php
$mysqli = new mysqli("localhost", "root", "root", "sms");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$old = $_POST['old'];
$new = $_POST['new'];
echo "Old: $old";
echo "<br /> New: $new";
mysqli_query("UPDATE klas SET klas_id='$new' WHERE klas_id='$old'");
ECHO "<br /><br />Updated.";
mysql_close($con);
?>
Code looks fine to me.. does anyone see the mistake? The table is not updating.
thanks
edit
So, more explanation: the table klas has just 1 column: klas_id. There’s a row: A3D. I’d like to change that into A3C, so I fill in ‘A3D’ in old and ‘A3C’ in new.
You’re mixing here Procedural and OO style.You can’t mix those two,the code should look something like this(not tested but should work)
Also be sure to escape those chars if you intend it for wider use