Skip to main content

How to connect Database to HTML page

Comments

8 comments

  • zaryab_helperst
    Hey, I am new to this platform. I designed a login page now i want to connect these credentials with Database. But i do not know how to connect with database.
    0
  • andrew.n
    First you have to create a database, a database user and a password. Login to cPanel, Go to MySQL database, create database there then go back and create a user. After that select the database and user then add permissions and you are good to go.
    0
  • zaryab_helperst
    I have done all this but still there is an issue. Domain hosting said its script issue.
    0
  • andrew.n
    What is the error you are getting exactly?
    0
  • zaryab_helperst
    I am not connection with database. I think i have issue in script. But i don't know how can i solve it.
    0
  • zaryab_helperst
    I have two files login.php and server.php. I want as a new user come it should enter usrname and password then it should be store in database. As in future registered user come authenticate username and password from database then redirect to the 'dashboard.html'. But i do not know whats the issue with that code i am not redirecting the other page. Not having any value in database. Please guide me Login. php Login

    Welcome Back!

    Remember Me
    Login

    Server.php )) { // receive all input values from the form $username = mysqli_real_escape_string($db, $_POST['username'>); $firstname = mysqli_real_escape_string($db, $_POST['firstname'>); $lastname = mysqli_real_escape_string($db, $_POST['lastname'>); $email = mysqli_real_escape_string($db, $_POST['email'>); $bankname = mysqli_real_escape_string($db, $_POST['bankname'>); $accountnumber = mysqli_real_escape_string($db, $_POST['accountnumber'>); $phonenumber = mysqli_real_escape_string($db, $_POST['phonenumber'>); $sponsor = mysqli_real_escape_string($db, $_POST['sponsor'>); $password = mysqli_real_escape_string($db, $_POST['password'>); // Finally, register user if there are no errors in the form if (count($errors) == 0) { $password = md5($password);//encrypt the password before saving in the database $query = "INSERT INTO users (username, firstname, lastname, email, bankname, accountnumber, phonenumber, sponsor, password) VALUES('$username', '$firstname', '$lastname', '$email', '$bankname', '$accountnumber', '$phonenumber', '$sponsor', '$password')"; mysqli_query($db, $query); $_SESSION['username'> = $username; $_SESSION['success'> = "You are now logged in"; header('Location: https://helperstree.com.ng/dashboard.html'); //echo ""; } } // ... // LOGIN USER if (isset($_POST['login_user'>)) { $username = mysqli_real_escape_string($db, $_POST['username'>); $password = mysqli_real_escape_string($db, $_POST['password'>); if (empty($username)) { array_push($errors, "Username is required"); } if (empty($password)) { array_push($errors, "Password is required"); } if (count($errors) == 0) { $password = md5($password); $query = "SELECT * FROM users WHERE username='$username' AND password='$password'"; $results = mysqli_query($db, $query); if (mysqli_num_rows($results) == 1) { $_SESSION['username'> = $username; $_SESSION['success'> = "You are now logged in"; header('Location: https://helperstree.com.ng/dashboard.html'); // echo ""; }else { array_push($errors, "Wrong username/password combination"); } } } ?>
    0
  • andrew.n
    You need to hire a PHP developer to look into your code then. This is not really a cPanel issue :(
    0
  • cPanelLauren

    You'd get the most help from looking up a tutorial on how to create this such as the following:

    https://phppot.com/php/php-user-registration-form/

    https://codewithawa.com/posts/complete-user-registration-system-using-php-and-mysql-database

     

    0

Please sign in to leave a comment.