Advertisement
Guest User

My love for php

a guest
Feb 8th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "xxxx";
  4. $username = "xxxx";
  5. $password = "xxxx";
  6. $dbname = "xxxx";
  7.  
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9.  
  10. if ($conn->connect_error) {
  11.     die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14.  
  15. function verifyCredentials($conn, $username, $password){
  16.     $pstm = $conn->prepare("SELECT * FROM xxxx WHERE xxxx =? AND xxxx =?");
  17.     $pstm->bind_param("ss", $username, $password);
  18.     $pstm->execute();
  19.     $pstm->store_result();
  20.     if ($pstm->num_rows > 0) {
  21.         echo 'Credentials correct';
  22.         } else {
  23.         echo 'Credentials incorrect';
  24.     }
  25.     $pstm->close();
  26. }
  27.  
  28. function incrementValue($conn, $username, $password) {
  29.     $pstm = $conn->prepare("SELECT xxxx FROM xxxx WHERE xxxx =? AND xxxx =?");
  30.     $pstm->bind_param("ss", $username, $password);
  31.     $pstm->execute();
  32.     $result = $pstm->get_result();
  33.     while ($row = $result->fetch_object()) {
  34.         $value = $row->aAttribute + 1; //Specify the attribute that you want to be incremented
  35.         echo $value;
  36.         $pstm = $conn->prepare("UPDATE xxxx SET xxxx = ? WHERE xxxx = ?");
  37.         $pstm->bind_param("is", $value, $username);
  38.         $pstm->execute();
  39.     }
  40.     $pstm->close();
  41. }
  42.  
  43. function fetchValue($conn, $value, $target) {
  44.     $pstm = $conn->prepare("SELECT ".$target." FROM xxxx WHERE xxxx = ?");
  45.     $pstm->bind_param("s", $value);
  46.     $pstm->execute();
  47.     $result = $pstm->get_result();
  48.    
  49.     while ($row = $result->fetch_object()) {
  50.         echo $row->$target;
  51.     }
  52.     $pstm->close();
  53. }
  54.  
  55. function appendToString($value) {
  56.     return $value." a string";
  57.  }
  58.  
  59. //incrementValue($conn, "xxxx", "xxxx");
  60. //fetchValue($conn, "xxxx", "xxxx");
  61. //verifyCredentials($conn, "xxxx", "xxxx");
  62. //echo appendToString("hello world");
  63.  
  64.  
  65. $conn->close();
  66.  
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement