Guest User

Untitled

a guest
Sep 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Php reads stuff</title>
  4. </head>
  5. <body>
  6. <h1>PHP reading the tables</h1>
  7.  
  8. <form method="post">
  9. <p>Kukan nimi:</p>
  10. <input type="text" name="name"><br>
  11. <p>Kukan väri:</p>
  12. <input type="text" name="color"><br>
  13. <input type="submit" value="Submit">
  14. </form>
  15. <br />
  16.  
  17. <?php
  18. //Mariadb login details
  19. $user='kukat';
  20. $password='Zla500EsaaJalpla';
  21. //php filen nimi johon tää formi palaa submitin jälkeen ex. index.php
  22. $filename = '';
  23.  
  24. //Connection (Establishing connection to my database on localhost.)
  25. $datab=$user;
  26. $dsn="mysql:host=localhost;charset=UTF8;dbname=$datab";
  27.  
  28. //OpeningConnection (New variable and a function? using the pre established variables of where, who and on what authority.)
  29. $pdo=new PDO($dsn, $user, $password);
  30.  
  31. //SQL Query (What I want to see from this connecion, the command to see it)
  32. $pdoStat=$pdo->prepare('Select * FROM superkukat;');
  33. $pdoStat->execute();
  34. $hits=$pdoStat->fetchAll();
  35.  
  36. //Print(what to print out)
  37. foreach($hits as $row) {
  38. echo "<p>".$row['id']. " ".$row['namee']. " ".$row['color']."</p>";
  39. }
  40.  
  41. //insert attempt (Stating what to get and the command to put it somewhere)
  42.  
  43. $name =$_POST["name"];
  44. $color = $_POST["color"];
  45. if("" !=$name){
  46. echo "<p>Uusi kukka</p>";
  47. $pdoStat=$pdo->prepare("INSERT INTO superkukat(namee, color) VALUES(:name, :color)");
  48. $pdoStat->bindParam(':name', $name);
  49. $pdoStat->bindParam(':color', $color);
  50. $pdoStat->execute();
  51. header("Location: $filename");
  52. exit();
  53. }
  54. ?>
  55.  
  56. <?php
  57. //Testing my PHP Works
  58. echo "Php ToiMii";
  59. ?>
  60. </body>
  61. </html>
Add Comment
Please, Sign In to add comment