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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -