I'm new to PHP and I need a bit of an assistance. I'm pretty sure that this has probably been one of the most common problems and has an easy fix but I've been trying. and I'll be so stupid about it
Alright, so here's my problem: every time I go to my localhost to try and open my PHP site It won't because I get this error every time.
"Parse error: syntax error, unexpected '$db' (T_VARIABLE) in C:\xampp\htdocs\exam\register.php on line 4"
here's my PHP code.
<?php
session_start()
$db = mysqli_connect("localhost", "root", "", "authentication");
if (isset($_POST['register_btn'])) {
session_start();
$username = mysql_real_escape_string($_POST['username']);
$emailaddress = mysql_real_escape_string($_POST['emailaddress']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['password2']);
if ($password == $password2) {
$password = md5($password);
$sql = "INSERT INTO users(username, email, password) VALUES ('$username', '$emailaddress', '$password')";
mysql_query($db, $sql);
$_SESSION['message'] = "You are now registered!";
$_SESSION['username'] = $username;
header("location: home.php");
}else {
$_SESSION['message'] = "The two passwords do not match";
}
}
?>