0

I'm trying to make a login page to learn basic PHP , first i want my seperate PHP file to store the input of the HTML file ( with a form ) , but when I press the button ( to trigger the POST to the PHP script ) I keep getting an unpleasing error.

Ive searched trough SO / internet , and i found similar people with my problem , but not the right solution for this problem ( atleast for my case ) Im pretty certain the problem has to do with structure / mapping , but I dont have a clue

my user login page :

  <form action="VerkoperApi.php" method="post">
    <p>Chose a username</p>
    <input type="text" placeholder="Username" id="Username" name="Username">
        <p>Choose a password</p>
    <input type="password" placeholder="Password" id="Password" name="Password">
        <p>Repeat password</p>
        <input type="password" placeholder="Repeat Password" id="RepeatPassword" name="RepeatPassword">

        <p id="ErrorMessage"></p>

        <p>Please enter e-mail address</p>
        <input type="email" placeholder="E-mail address" id="Email" name="Email">
        <p></p>
         <input type="submit" value="Submit" name="submit">

My Php file :

<?php

if(isset($_POST["submit"]))
    {

$link = mysqli_connect("localhost" , "root" , "" , "MyDBName");


if ($link == false)
{
die("No connection")
}
else    
{

$uname = $_POST['Username'];
$upass = $_POST['Password'];
$umail = $_POST['Email'];



}
?>

Im working in Framework 7 , and my .php file is in the same folder as my html page , so in my folder you will find : /Framework7-1.6.5/dist/index.html & /Framework7-1.6.5/dist/VerkoperApi.php

this is the error i'm getting : Cannot POST /Framework7-1.6.5/dist/VerkoperApi.php

If you need any more information , feel free to ask!

THEoneANDonly
  • 382
  • 1
  • 2
  • 16
  • Using the `mysql_` functions is extremely bad. They were deprecated in PHP 5 and removed in PHP 7. [See this post](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for more information. – Spencer Nov 01 '17 at 12:48
  • Thanks , but this solves a diffrent problem. i'm still not able to POST the data from my HTML to my PHP file – THEoneANDonly Nov 01 '17 at 12:52

1 Answers1

0

Since you want to use it to learn basic PHP, you can create values for the $uname, $pass and $umail variable instead of using $_POST['name'], but i can see you created a database for your learning so you have to create a table which will contain the users name, password and email and then use your php code to check if user details are true or false, and then redirect/show a successful message or take logged user to a specific page.

Or you can try this basic login code;

<?php
$link = mysqli_connect('your database details');
    session_start();

        if(isset($_POST['submit'])) {
                $username = $_POST['username'];
                $password = $_POST['password'];

                $ardp_login_query = mysqli_query($link "SELECT * FROM users WHERE username = '$username' AND password='$password'");
            $rows = mysqli_num_rows($link);
            if($rows > 0) {

                // session properties
                $_SESSION['id'] = $id;
                $_SESSION['username'] = $username;

                // take user back to index page
                header("location: home.php?user=$username");
            } else {
                echo = '<font color="red">Login failed, check username or password</font>';
            } 
        mysqli_close($link);
    } 
?>

and you also forgot to close your <form></form> tag

Dev.aaron
  • 286
  • 1
  • 3
  • 11
  • Yes i do have the database , but I'd like the user to register here , and then later i want to use the user's input to be in the database , not what i chose , am I wrong trying to POST the variables like this? as i'm understanding , you POST the variables the user types in the html to the PHP script , where you can later add these with sql to the DB? – THEoneANDonly Nov 01 '17 at 12:56
  • i think you need to search on how to create a login page using php – Dev.aaron Nov 01 '17 at 13:03
  • I did , that is what got me in this situation – THEoneANDonly Nov 01 '17 at 13:07
  • That's definitely what he is doing, the problem is he can't access those POST variables – Alleo Indong Nov 01 '17 at 13:17
  • I didnt forget to close it , its just not included in the example , I still can't access the variables – THEoneANDonly Nov 01 '17 at 13:58
  • Let me correct myself in the code shown , also , i just wanted to keep you an update that this isnt the right solution , ive actually been searching for hours , but i think i'm going to solve this problem with a diffrent solution , because i'm getting a headache :-) – THEoneANDonly Nov 01 '17 at 17:01
  • funny, please remove the down vote you are actually increasing more to my ban – Dev.aaron Nov 01 '17 at 22:04
  • I dont understand what you think is comical here , plus I haven't voted down on your answer , but i'll give you a vote up :) By the way , the soloution you gave me is to check if it excists , Im trying to put it Inside the DB – THEoneANDonly Nov 05 '17 at 22:25