php - Edit Value in MySQL Database -
i trying edit value of integer in database through php, here code using
$query = "update bremners stud_name = john set stud_goal = stud_goal + 1";
bremners table , in table there column name of person (stud_name) tried making if stud_name = john change int represents number of goals john has, column has number of goals stud_goal. tried increasing value 1.
try this:
$query = "update bremners set stud_goal = stud_goal + 1 stud_name = 'john'";
in php start this:
<?php $mysqli = new mysqli("localhost", "root", "", "test"); $name = "bill"; $increment = 1; if ($stmt = $mysqli->prepare("update bremners set stud_goal = stud_goal + ? stud_name = ?")) { $stmt->bind_param("is", $increment, $name); $stmt->execute(); printf("%d row affected.\n", $stmt->affected_rows); $stmt->close(); } $mysqli->close(); ?>
if need change multiple values multiple amounts, should use write query way:
$mysqli->prepare("update bremners set stud_goal = stud_goal + ?, stud_assist = stud_assist + ? stud_name = ?")
?
placeholders, have bind parameters way:
$stmt->bind_param("iis", 1, 5, "john");
- this replace first ? 1 of type "i" (integer)
- the second ? 5 of type "i" (integer)
- the third ? "john" of type "s" (string)
please have @ link.
Comments
Post a Comment