Hi all, learner here.
I have been told to validate a form with a username and password using php and a mysql database.
So to do this I need to database to validate against.
I have created one in phpmyadmin / xampp called mydb. I can successfully connect to this database using
<?php
// Create connection
$con=mysqli_connect("localhost","userdb","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else { echo "<h1>You're connected to userdb</h1>"; }
?>
In this database I created a table called 'users, and in this table I created two, “rows” I think they are called?, called ‘name’ and ‘password’. I’m not really sure what the primary key for this is, because I’m confused by the interface, but I think/hope it’s the name, because that was the first one I created.
Now moving on, hopefully?, I have created a webform with simple username / password fields
<h2>Enter your username and password</h2>
<br/><br/>
<h1>Name:</h1> <input type="text" name="name"> <br>
<h1>Password:</h1> <input type="text" name="password">
</div>
And basically here is the point I am up to.
I thought the first thing I would do is create two php variables to store the username and password in.
<?php
$name = "";
$pw = "";
?>
And from here I don’t really know where to go. There is a tutorial here on Sitepoint that shows some validation, but it’s not putting anything into a databse. Just validating with php.
Help, tips, pointers?
Here is my whole html document, called index.php
<html>
<head>
<style>
#main
{
width: 700px;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="main">
<?php
// Create connection
$con=mysqli_connect("localhost","userdb","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else { echo "<h1>You're connected to userdb</h1>"; }
?>
<?php
$name = "";
$pw = "";
?>
<h2>Enter your username and password</h2>
<br/><br/>
<h1>Name:</h1> <input type="text" name="name"> <br>
<h1>Password:</h1> <input type="text" name="password">
</div>
</body>
</html>