No Connection to MySQL Sever

Problems with the Windows version of XAMPP, questions, comments, and anything related.

No Connection to MySQL Sever

Postby g0oddy » 22. September 2017 01:10

My php code is right, but it is unable to connect to the database I have in MySQL. XAMPP is running, both Apache and MySQL are green. The problem I think is that my XAMPP is on an external drive as my work is on my actual computer. I am more than willing to attach images, here is my php code in the html that is trying to submit data.
Code: Select all
<?php
$servername = "localhost";
$username = "XXXX";
$password = "XXXX";
$dbname = "XXXX";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$role = $_POST["role"];

$sql = "INSERT INTO classroom (firstname, lastname, email, role)
VALUES ('$firstname', '$lastname', '$email', '$role')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
   echo "Something went wrong with your input information please try again.";
   /*Check Error Message*/
    /*echo "Error: " . $sql . "<br>" . $conn->error;*/
    echo "<br>" . $conn->error;
}

$conn->close();
?>
g0oddy
 
Posts: 1
Joined: 22. September 2017 00:59
XAMPP version: 3.2.2
Operating System: Windows 10

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 272 guests