Not really clued up on switches, so any help converting this would be appreciated!
<?php
session_start();
require("includes/connect.php");
$post_username = $_POST['username'];
$post_password = $_POST['password'];
if($post_username && $post_password)
{
if(strlen($post_username)>25 || strlen($post_password)>25)
{
die("Username or password is too long!");
}
else
{
//convert password to md5
$post_password = md5($post_password);
//query the database
$login = sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'", mysql_real_escape_string($post_username), mysql_real_escape_string($post_password));
$rowcount = mysql_num_rows(mysql_query($login));
$fieldarray = mysql_fetch_assoc(mysql_query($login));
$id = $fieldarray['id'];
if($rowcount == 1)
{
$_SESSION['user']=$post_username;
$_SESSION['id']=$id;
echo $_SESSION['user'].", you have been logged in! <a href='index.php'>Back to main page</a>";
}
else
{
die("Incorrect username or password!");
}
}
}
else
die("Username and password required!");
include('includes/analytics.php');
?>
Thank you 🙂