Forum Moderators: coopster
I'd start by leaning how to do simple mysql connections and queries. (mysql_connect, mysql_query) and then you can build an slightly more advanced query to test if login is correct.
if(mysql_num_rows(mysql_query("SELECT id,name,email FROM users WHERE user = mysql_real_escape_string($_POST['username']) AND pass = mysql_real_escape_string($_POST['password']) AND active = 1 LIMIT 1")) > 1){
//login in
} else { die ('user not found'); }
but as i say you will need to know MYSQL before you could use that, and you would want to do more robust testing on user inputs that just mysql_real_escape_string()
Good luck, learning. :-)
Here is some code..sample for you know my level..
<html>
<link href="style3.css" rel="stylesheet" type="text/css">
<body>
<div class="container">
<div class="center">
<form action="insert.php" method="post">
<br/>
<p><b> Name: </b></p> <input type="text" name="name" class="afilter"/>
<p><b> Lastname: </b></p> <input type="text" name="lastname" class="afilter"/>
<p><b> Phone: </b></p> <input type="text" name="phone" class="afilter"/>
<p>
<input type="submit" value="Submit"/>
</p>
<a href="home.php">Home</a>
<br/>
<br/>
</form>
</div>
</div>
</body>
</html>
---------------------------
And here index.php
<html>
<link href="style3.css" rel="stylesheet" type="text/css">
<body>
<div class="container">
<div class="center">
<?php
$connection = mysql_connect("localhost","","")
or die("no connection");
if (isset($connection))
{
echo("<br/><p><b> Connection is working </b></p><br/>");
}
mysql_select_db("customers", $connection);
$sql="INSERT INTO customers (name, lastname, phone)
VALUES
('$_POST[name]','$_POST[lastname]','$_POST[phone]')";
if (!mysql_query($sql,$connection))
{
die('Error: ' . mysql_error());
}
echo "<p><b> 1 Information added </b></p>";
mysql_close($connection)
?>
<br/>
<a href="home.php">Home</a>
</div>
</div>
</body>
</html>
Maybe its full of mistakes but anyway it works on my web site.
So i can inster information to batabase that i made myself too, but how i can make login.php that it checks information from my database? Or can i do it like that? Sorry my stupid questions! But im happy if i can make you laugh :)
you could also use it to improve security on your current script. as atm you are putting raw user inputs straight into the db, which is NEVER a good idea.
Good Luck.
Alan