Login fails when testing

Ok so I have put together a login parse, a connections code with an index page and configured phpadmin with a database with a user but I can’t seem to login to the site when I’m testing it, I get the invalid login. here is the code I use, I also use dreamweaver.

I JUST WANT TO SAY THAT I FIGURED THIS OUT, SO NO NEED TO POST TO THIS.

index.php
[php]<?php
if (!isset($_SESSION[‘uid’])) {
echo "
Username:  
Password <input type=‘password’ name=password’ /> 
<input type=‘submit’ name=‘submit’ value=Log In’ />
";
} else {
echo “

You are logged in as “.$_SESSION[‘username’].” • Logout”;
}
?>[/php]

Connections.php
[php]<?php
$host = “localhost”;
$username =“root”;
$password = “”;
$db = “forum”;
mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($db);
?>[/php]

login_parse.php
[php]<?php

session_start();
include_once(“connect.php”);

if (isset($_POST[‘username’])) {
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$sql = “SELECT * FROM users WHERE username=’”.$username."’ AND password=’".$password."’ LIMIT 1";
$res = mysql_query($sql) or die(mysqle_error());
if (mysql_num_rows($res) == 1) {
$row = mysql_fetch_assoc($res);
$_SESSION[‘uid’] = $row[‘id’];
$_SESSION[‘username’] = $row[‘username’];
header(“Location: index.php”);
exit();
} else {
echo “Invalid login information. Please return to the previous page.”;
exit();
}
}

?>[/php]

There actually is a need to post to this. You are using deprecated code. Use PDO or Mysql.

I don’t know what your talking about, never heard of either of them, I just started studying php and MySQL v_v

Look it up. You are learning the wrong code that is no longer supported and will not even work in the next releases of php. I have provided a complete working PDO database that will have you up and running in seconds. Start your learning from this and you will do well for yourself. You are wasting your time with the code you posted.

http://www.phphelp.com/forum/the-occasional-tutorial/beginners-pdo-bumpstart-code-use-it-now!

can you recommend any site or source to study it, I can google it but if you have a good source I’d really appreciate it, guess I have to scrap my work thus far though.

This should help get you going.

http://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly–net-25338

ok so your still using the MySQL database but just using PDO as a different way to connect to it?

Yes, but even more importantly is you are now using prepared statements.

Sponsor our Newsletter | Privacy Policy | Terms of Service