- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>test</title>
- </head>
- <body>
- This is firt test<br>
- <?php
- $conStr = "pgsql:host=ec2-34-198-243-120.compute-1.amazonaws.com;port=5432;dbname=d33tv102tftng6;user=zdnbsjhbujtaca;password=4e00d5400a3b2f211a31dae4b7b679212d0e7c72763659cd5337b6e8b1f4227e";
- $pdo = new \PDO($conStr);
- $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
- if(isset($_POST["uname"]) && isset($_POST["password"]) && $_POST["uname"] != "" && $_POST["password"] != "")
- {
- $sql = 'INSERT INTO usertb(uname,pass) VALUES(:uname,:pass)';
- $stmt = $pdo->prepare($sql);
- // pass values to the statement
- $stmt->bindValue(':uname', $_POST["uname"]);
- $stmt->bindValue(':pass', $_POST["password"] );
- // execute the insert statement
- $stmt->execute();
- // return generated id
- //echo $pdo->lastInsertId();
- }
- $stmt = $pdo->query('SELECT uname, pass FROM usertb');
- while ($row = $stmt->fetch(\PDO::FETCH_ASSOC))
- echo $row['uname'].",".$row['pass']."<br>";
- ?>
- <form action="" method="post">
- Account:<input type=text name=uname><br>
- Password:<input type=password name=password><br>
- <input type=submit value='insert'>
- </form>
- </body>
- </html>
複製代碼 |