Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Can you help me here ! 

I get this wrong in my PHP code when I open it in localhost.  

 


Fatal error: Uncaught mysqli_sql_exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond in C:\xampp\htdocs\labb4\moment3.php:18 Stack trace: #0 C:\xampp\htdocs\labb4\moment3.php(18): mysqli->__construct('studentmysql.mi...', 'arkh2000', 'qc18cg6j', 'arkh2000') #1 {main} thrown in C:\xampp\htdocs\labb4\moment3.php on line 18
 
The code is : 

<?php $page_title = "Moment 3 - Linneas Gästbok"; ?>
    <?php include("includes/header.php"); ?>

    <?php include("includes/mainmenu.php"); ?>

    <article class="mainContent">

    <?php echo "<h1>$page_title</h1><br/>"; ?>

    <article class="guestbook-container">

    <div class="left-flexbox">

    <?php
    
    $db =  new mysqli(DBHOST, DBUSER, DBPASS, DBDATABASE);
    //$db =  new mysqli(DBHOST, DBUSER, DBPASS, DBDATABASE);
        if($db->connect_errno > 0) {
        die("Fel vid anslutning: " . $db->connect_error);
    }

    if(isset($_POST['user'])) {
        $user = $_POST['user'];
        $content = $_POST['content'];

        // Lägg till data
        $sql = "INSERT INTO guestbook(user, content)VALUES('$user', '$content')";
        $result = $db->query($sql);
    }

    ?>

    <h3>Lämna en kommentar</h3>

    <form action="moment3.php" method="post">
    <label for="user">Ditt namn: </label>
    <input type="text" name="user" id="user">
    <br/>
    <br/>
    <label for="content">Ditt meddelande:</label>
    <textarea class="textrutan-message" name="content" id="content" rows="10" cols="30"></textarea>
    <br/><br/>
    <input type="submit" name="postMessage" value="Posta ditt inlägg"><br/>
    </form>
    </div>

    <div class="right-flexbox">
    <?php

    // SQL-fråga

    $sql = "SELECT * from guestbook ORDER BY created DESC";
    $result = $db->query($sql);

    while($row = $result->fetch_assoc()) {
        ?>

    <div class='div-containing-message'><h3><?= $row['user']; ?></h3>
    <p> <?= $row['content']; ?></p>
    <h4> <?= $row['created']; ?></h4></div>

        <?php
    }
    ?>

    </div>

    </article>

     <?php include("includes/footer.php"); ?>

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education