Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic PHP-script doesn't work
    primarykey
    data
    text
    <p>I'm new to PHP and SQL but I'm trying to create a simple PHP-script that allows a user to login to a website. It doesn't work for some reason and I can't see why. Every time I try to login with the correct username &amp; password, I get the error "Wrong Username or Password". The database-name and table-name are correct.</p> <p><strong>connect.php:</strong></p> <pre><code>&lt;?php $db_host = 'localhost'; $db_name = 'app'; $db_user = 'root'; $db_pass = ''; $tbl_name = 'users'; // Connect to server and database mysql_connect("$db_host", "$db_user", "$db_pass") or die("Unable to connect to MySQL."); mysql_select_db($db_name)or die("Cannot select database."); // Info sent from form $user = trim($_POST['user']); $pass = trim($_POST['pass']); // Protection against MySQL injection $user = stripslashes($user); $pass = stripslashes($pass); $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $sql = ("SELECT * FROM $tbl_name WHERE username='$user' and password='$pass'"); $result= mysql_query($sql); $count 0= mysql_num_rows($result); if($count==1){ // Register $user, $pass send the user to "score.php" session_register("user"); session_register("pass"); header("location:score.php"); } else { echo "Wrong Username or Password"; } ?&gt; </code></pre> <p><strong>score.php:</strong></p> <pre><code>&lt;?php session_start(); if(!session_is_registered(user)){ header("location:login.html"); } ?&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;Login Successful&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I hope someone can find my mistake, thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload