简体   繁体   中英

Using php file in notepad++ to connect to XAMPP SQL

Hello I am currently doing a school project where I have to produce an application on android. Recently I began making the login/register page ,however I am new to PHP so i am unable to connect to my php file due to current errors. I was wondering if it was due to the database username being incorrect as when I installed XAMPP I was required to change the port numbers so it could work. The following code that i'm having difficulty with is:

<?php
$servername = "localhost:8080"; 
$username = "root";  
$password = ""; 
$dbname = "db_client";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

?>

Due to this I am unable to connect(connection) to my login page:

<?PHP 
include_once("connection.php"); 
if( isset($_POST['txtUsername']) && isset($_POST['txtPassword']) ) { 
    $username = $_POST['txtUsername'];
    $password = $_POST['txtPassword'];

    $query = "SELECT username, password FROM tbl_client ". 
    " WHERE username = '$username' AND password = '$password'"; 

    $result = mysqli_query($conn, $query);

    if($result->num_rows > 0){
            echo "success";  
    } 
    else{ 
        echo "Login Failed <br/>"; 
    } 
} 
?>

 <html> <head><title>Login|Matt</title></head> <body> <h1>Login Example</h1> <form action="<?PHP $_PHP_SELF ?>" method="post"> Username <input type="text" name="txtUsername" value="" /><br/> Password <input type="password" name="txtPassword" value="" /><br/> <input type="submit" name="btnSubmit" value="Login"/> </form> </body> </html 

Any ideas on the issue will be very much appreciated =)

remove the port 8080 from your server name. it is not the default port for mysql. 3306 is the default port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM