Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Php reads stuff</title>
- </head>
- <body>
- <h1>PHP reading the tables</h1>
- <form method="post">
- <p>Kukan nimi:</p>
- <input type="text" name="name"><br>
- <p>Kukan väri:</p>
- <input type="text" name="color"><br>
- <input type="submit" value="Submit">
- </form>
- <br />
- <?php
- //Mariadb login details
- $user='kukat';
- $password='Zla500EsaaJalpla';
- //php filen nimi johon tää formi palaa submitin jälkeen ex. index.php
- $filename = '';
- //Connection (Establishing connection to my database on localhost.)
- $datab=$user;
- $dsn="mysql:host=localhost;charset=UTF8;dbname=$datab";
- //OpeningConnection (New variable and a function? using the pre established variables of where, who and on what authority.)
- $pdo=new PDO($dsn, $user, $password);
- //SQL Query (What I want to see from this connecion, the command to see it)
- $pdoStat=$pdo->prepare('Select * FROM superkukat;');
- $pdoStat->execute();
- $hits=$pdoStat->fetchAll();
- //Print(what to print out)
- foreach($hits as $row) {
- echo "<p>".$row['id']. " ".$row['namee']. " ".$row['color']."</p>";
- }
- //insert attempt (Stating what to get and the command to put it somewhere)
- $name =$_POST["name"];
- $color = $_POST["color"];
- if("" !=$name){
- echo "<p>Uusi kukka</p>";
- $pdoStat=$pdo->prepare("INSERT INTO superkukat(namee, color) VALUES(:name, :color)");
- $pdoStat->bindParam(':name', $name);
- $pdoStat->bindParam(':color', $color);
- $pdoStat->execute();
- header("Location: $filename");
- exit();
- }
- ?>
- <?php
- //Testing my PHP Works
- echo "Php ToiMii";
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment