Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- </head>
- <body>
- <h2>Insert your Bangla data</h2>
- <form method="post" action="indexx.php">
- <p>Your Name:</p> <input type="text" name="fullname" placholder="Your name"> <br>
- <textarea cols="20" rows="8" name="textBox" placeholder="Write down your query please"></textarea>
- <br>
- <input type="submit" name="sendData" value="submit">
- </form>
- </body>
- </html>
- here is codes of indexx.php
- <?php
- include('database.php');
- $database = new DB;
- $database->set_db("localhost", "ourcms", "root", "");
- $conn = $database->connect();
- if (isset($_POST['sendData']))
- {
- $name = $_POST['fullname'];
- $texts = $_POST['textBox'];
- $stmt = $conn->prepare('INSERT INTO tests(fname, bodytext) VALUES(:allname, :textbody)');
- $stmt->execute(array(':allname' => $name, ':textbody' => $texts));
- }
- $results = $conn->query('SELECT * FROM tests')->fetchAll(PDO::FETCH_ASSOC);
- ?>
- <?php if(isset($_POST['sendData'])) : ?>
- <?php foreach( $results as $result) : ?>
- <li> <?php echo $result['fname']; ?></li> <br>
- <li> <?php echo $result['bodytext']; ?> </li>
- <?php endforeach; endif; ?>
- // Codes below for database.php
- <?php
- class DB
- {
- private $dbHost;
- private $dbName;
- private $dbUser;
- private $dbPass;
- protected $con;
- function set_db($host, $db, $user, $pass)
- {
- $this->dbHost = $host;
- $this->dbName = $db;
- $this->dbUser = $user;
- $this->dbPass = $pass;
- }
- function connect()
- {
- $info = 'mysql:host='.$this->dbHost.';dbname='.$this->dbName;
- try
- {
- $this->con = new PDO($info, $this->dbUser, $this->dbPass);
- }
- catch(PDOException $e)
- {
- print "Error Founds: ".$e->getMessage();
- die();
- }
- return $this->con;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement