Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username='root';
- $password='';
- $num = 0;
- $num = $_GET['num'];
- class Insert{
- function Inserting($id){
- $username='root';
- $password='';
- try{
- $db = new PDO("mysql:host=localhost;dbname=internal_announcement_board;port=3307",$username,$password);
- $sql = "INSERT INTO announcements (user_id,
- title,
- content) VALUES (
- :user_id,
- :title,
- :content)";
- $stmt = $db->prepare($sql);
- $stmt->bindParam(':user_id', $id);
- $stmt->bindParam(':title', $_POST['title']);
- $stmt->bindParam(':content', $_POST['content']);
- $stmt->execute();
- if($stmt){ ?>
- <script type="text/javascript" >
- // alert("Success");
- </script>
- <?php
- }else{ ?>
- <script type="text/javascript" >
- alert("Fail");
- </script>
- <?php
- }
- }catch(PDOException $e){
- echo $e->getMessage();
- }
- }
- function ViewAll(){
- $username='root';
- $password='';
- try {
- $dbh = new PDO("mysql:host=localhost:3307;dbname=internal_announcement_board",$username,$password);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "SELECT * FROM `users` ORDER BY `id`";
- foreach ($dbh->query($sql) as $row) {
- $sql2 = "SELECT * FROM `announcements` WHERE `user_id` = ". $row['id'];
- foreach ($dbh->query($sql2) as $row2) {
- echo "<h4>By: ".$row['first_name']." ".$row['last_name']." on ".$row['created_at']."</h4><br>";
- echo "<h2>".$row2['title']."</h2><br><br>";
- echo "<h4>".$row2['content']."</h4><br><br>";
- echo "<hr color='black'><br><br>";
- }
- }
- }catch(PDOException $e){
- echo $e->getMessage();
- }
- }
- }
- $a = $_GET['a'];
- $dbh = new PDO("mysql:host=localhost:3307;dbname=internal_announcement_board",$username,$password);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql= "SELECT * FROM users WHERE username = '".$a."'";
- foreach ($dbh->query($sql) as $row) {
- echo "<h1>Welcome ".$row['first_name']." ".$row['last_name']."</h1>";
- $id = $row['id'];
- }
- if(isset($_POST['sub'])){
- $num = 0;
- header("Location: index.php");
- }
- if(isset($_POST['sub2'])){
- $insert = new Insert();
- $insert -> Inserting($id);
- }
- if($num > 0){
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
- <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
- </head>
- <body style="margin:10%;">
- <form method="POST">
- <input type="submit" name="sub" value="Logout" class="btn btn-danger" style="float: right; margin-top:-150px;"/></td>
- <br>
- <label>Title</label>
- <input type="text" name="title" class="form-control">
- <label>Announcement</label>
- <textarea name="content" class="form-control"></textarea><br/>
- <input type="submit" name="sub2" value="Submit" class="btn btn-success" />
- </form>
- <script type="text/javascript" src="jquery-3.1.1.min.js"></script>
- <br><br><br>
- </body>
- </html>
- <?php
- $insert = new Insert();
- $insert -> ViewAll();
- }else{
- header("Location: index.php");
- }
- ?>
Add Comment
Please, Sign In to add comment