I’m new to coding and I’m currently struggling to connect my signup page to phpmyadmin.The username, password, host, and database name are all correct.
Result of code
Sign in page:
'<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$host = "127.0.0.1";
$dbUsername = "root";
$dbPassword = "";
$dbName = "website_db";
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM Users WHERE user_name = ?AND paswd = ?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$_SESSION['logged_in'] = true;
header("Location: main_page.php");
exit();
}
else {
echo "<p>Invalid username or password!</p>";
}
$stmt->close();
$conn->close();`
}
?>`
I’ve tried checking the config. inc. php file to check if the username, password,and host are correct (they are) and tried reinstalling xampp to see if that would work as well. I’ve also tried switching between 127.0.0.7 and localhost for the host name as well.
David Heurtevant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.