Hi there
I really want to code a blog myself and have decided the best way for me to do this as Im a newcomer is to take it slowly and do it bit by bit.
The first part I want to build is the login part. Im guessing this is a different script for register…
Ive been reading and watching loads of tutorials but am finding it quite hard. May I post some code and you can tell me what you think…?
session_start();
$username = $_POST["username"];
$password = $_POST["password"];
if($username&&$password)
{
$connect = mysql_connect("localhost", "root", "")
|| die ("Couldn't log you in!");
$query = mysql_query("SELECT * FROM users WHERE username = '$username.'");
$numrows = mysql_num_rows('$query');
if ($numrows !=0)
{
while ($row = mysql_fetch_assoc ($query))
{
$dbusername = $row ["username"];
$dbpassword = $row ["password"];
}
//check to see if they match!
if ($username = $dbusername && $password = $dbpassword);
{
echo "You're in!";
$_SESSION["username"] = $username;
}
echo "Incorrect login!";
}
else
die ("That user doesn't exist");
mysql_select_db("php_login") or die ("Couldn't connect to database");
}
else
die("Please check and enter your username and password");
I have followed this from a tutorial and could I believe write somethng based off this myself but Im a bit worried about the ‘$connect’ variable. As you can see it specifies “my” admin details. If I was to use this code and attach it to a form a new user/follower was filling in, is this wise…does it need to be there…?
Any suggestions would be great as I wanna get each script I write as good as it can be before I move onto the next one.
PS thanks to everyone that has helped me so far.