Q: Basic PHP Registration/Login System I'm trying to create a very basic registration and login system in PHP. I am very new to this, so I followed a video on YouTube. I'm guessing my problem is that I'm using some function that may have been depreciated in PHP 7. I have included the code I have below. What should I correct? I know I don't have much error handling or such yet. I just want to get the basics down and create a page where the user can register, login, and then have their user id or name displayed on the page. I got that part to work, but nothing shows up in the database when I log in. Also, how do you get the host name? I'm using a webhosting service, and not working locally. Thank you for your help!
dbh.php:
<?php

$conn = mysqli_connect("localhost", "usernamehere", "passwordhere",
"mylogindatabase");
if(!$conn)
{
die("Connection failed: ".mysqli_connect_error());
}

?>

welcome.php:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<form action="login.php" method="POST">
<input type="text" name="uid" placeholder="Username">
<br />
<input type="password" name="pwd" placeholder="Password">
<br />
<button type="submit">LOGIN</button>
</form>

<?php
if(isset($_SESSION['id']))
{echo $_SESSION['id'];}
else{
echo "You are not logged in!";
}
?>
<br />
<br />
<br />
<form action="signup.php" method="POST">
<input type="text" name="first" placeholder="First Name">
<br />
<input type="text" name="last" placeholder="Last Name">
<br />
<input type="text" name="uid" placeholder="Username">
<br />
<input type="password" name="pwd" placeholder="Password">
<br />
<button type="submit">SIGN UP</button>
</form>

<br />
<br />
<br />

<form action="logout.php">
<button>Log Out</button>
</form>

</body>
</html>

signup.php:
<?php
session_start();
include 'dbh.php';

$first = $_POST['first'];
$last = $_POST['last'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];

echo $first;
echo $last;
echo $uid;
echo $pwd;

$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first, $last, $uid, $pwd')";
$result = $conn->query($sql);
header("Location: welcome.php");

?>

login.php:
<?php
session_start();
include 'dbh.php';

$uid = $_POST['uid'];
$pwd = $_POST['pwd'];

echo $first;
echo $last;
echo $uid;
echo $pwd;

$sql = "SELECT * FROM user WHERE uid='$uid' AND 
pwd='$pwd'";
$result = $conn->query($sql);

if(!$row = $result->fetch_assoc())
{
echo "Your username or password is incorrect!";
} else{
$_SESSION['id'] = $row['id'];
}

header("Location: welcome.php");

?>

logout.php:
<?php
session_start();
session_destroy();
header("Location: welcome.php")
?>


A: Your insert query should be like this : 
$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first', '$last', '$uid', '$pwd')";

Read this for host : http://php.net/manual/en/function.gethostname.php

EDIT: While this will work and will execute correctly, be warned that
  your application will be vulnerable to SQL injection attacks without
  the proper countermeasures, so when using MySQLi try to use prepared
  statements instead of concatenated queries as they are vulnerable
  against SQL injection. This might seem complicated and tedious at
  first for beginners, but it is very necessary to keep your application
  secure. You can use either prepared statements which are preferable or
  simply escape the variables (less secure) 

Read more here:
http://php.net/manual/en/mysqli.prepare.php
http://php.net/manual/en/mysqli.real-escape-string.php

A: you have small error in your sql query
$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first', '$last', '$uid', '$pwd')";

learn more about sql inset query at
http://www.w3schools.com/sql/sql_insert.asp

A: You have typo mistake in your code. You forgot quotes in your query 
So instead of this 
$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first, $last, $uid, $pwd')";

use this 
$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first', '$last', '$uid', '$pwd')";

Also,if you want to explore more then you can see this docs

A: Maybe you forget in :
$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first, $last, $uid, $pwd')";

Your query should be:
$sql = "INSERT INTO user (first, last, uid, pwd) 
VALUES ('$first', '$last', '$uid', '$pwd')";

If you need the example of how to create login multiuser, read more:
Detailed Technology Center
