fork download
  1. <?php
  2.  
  3. // your code goes here
  4. //the function
  5. function update($data,$where)
  6. {
  7. try {
  8. $dns ="mysql:dbname=students;host=127.0.0.1;port=3306;";
  9. $usre="root";
  10. $password ="";
  11.  
  12. $db =new PDO($dns, $usre, $password);
  13.  
  14. $query = "UPDATE `student' SET $data WHERE $where";
  15. // print($query);
  16. $stmt=$db->prepare($query);
  17. // $stmt->bindParam(":x", $us, PDO::PARAM_STR);
  18.  
  19. $stmt->execute();
  20. echo $stmt->rowCount();
  21. if($stmt->rowCount()>0)
  22. {return 'updated';}
  23. else
  24. return 'unupdated';
  25.  
  26. } catch(PDOException $e) {
  27. echo "Error: " . $e->getMessage();
  28. return null;
  29. }
  30. }
  31. // the upsatedo
  32. var_dump($_POST['username']);
  33. $data = "'fname' = '" . $_POST['first'] . "'";
  34.  
  35. $where = "'user' = '" . $_POST['username'] . "'";
  36. include_once("functions.php");
  37. $res = update($data, $where);
  38. echo $res;
Success #stdin #stdout #stderr 0.03s 26112KB
stdin
Standard input is empty
stdout
NULL
Error: could not find driver
stderr
PHP Notice:  Undefined index: username in /home/caUBFd/prog.php on line 32
PHP Notice:  Undefined index: first in /home/caUBFd/prog.php on line 33
PHP Notice:  Undefined index: username in /home/caUBFd/prog.php on line 35
PHP Warning:  include_once(functions.php): failed to open stream: No such file or directory in /home/caUBFd/prog.php on line 36
PHP Warning:  include_once(): Failed opening 'functions.php' for inclusion (include_path='.:/usr/share/php') in /home/caUBFd/prog.php on line 36