I am very new to PHP and have been following online tutorials.
I have created a site with a database. I can retrieve information from my database and display it at the moment.
I am trying to create a log in page that checks if the user is in the database and if not they cannot log in.
I have:
login1.php
- Code: Select all
<?php
$current_file = $_SERVER['SCRIPT_NAME'];
?>
login.php
- Code: Select all
if (isset($_POST['username'])&&isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$passwordhash = md5($password);
if (!empty($username)&&!empty($password)) {
$query = "SELECT id FROM users WHERE username='$username' AND password='$passwordhash'";
if ([u][b]$query_run = mysql_query($query[/b][/u]));{
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0){
echo 'Invalid username or password';
} else if ($query_num_rows==1){
echo 'Logged in.';
}
}
} else {
echo 'You must enter a username and password.';
}
}
?>
<form action = "<?php echo $current_file; ?>" method ="POST">
Username: <input type ="text" name ="username">
Password: <input type ="password" name ="password">
<input type ="submit" name ="Login">
</form>
My problem is where I have underlined. The error message is "Accidental assignment in a condition"
It wants me to change the '=' to '==' or '===' but these don't work either.
When attempting to put a username and password in on the website these are the error messages:
Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/sgh997/testPHP1/templates/login.php on line 14
Warning: mysql_query(): A link to the server could not be established in /home/sgh997/testPHP1/templates/login.php on line 14
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/sgh997/testPHP1/templates/login.php on line 15
(Line 14 is underlined and bold)
Please help as I have following the instructions online perfectly!
Thank you

