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 :                  $page_title"; ?>             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);     }     ?>     Lämna en kommentar         Ditt namn:                 Ditt meddelande:                             query($sql);     while($row = $result->fetch_assoc()) {         ?>                                  php in

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Fundamentals of Blockchaining
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education