Forum Moderators: coopster

Message Too Old, No Replies

php register and login scripts

         

noora

5:24 pm on Jan 1, 2010 (gmt 0)

10+ Year Member



Help!
Can someone tell me very very simple php registration and login script.. i have been trying everything what i found from internet but all of them have anyway some mistakes and i am newbie in this so how should i know to correct it.. :)
i am using wampserver

Kings on steeds

7:28 pm on Jan 1, 2010 (gmt 0)

10+ Year Member



well, I'm not sure you can have a "simple" registration and login script, if you don't understand PHP at all. you will need a MYSQL database to store users values, and you will need a way to validate them...

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. :-)

noora

8:09 pm on Jan 1, 2010 (gmt 0)

10+ Year Member



Who told you that i dont know mysql? :) I can create databases etc.. But my problem is that i dont have time to learn little by little just now, that how i make those codes myself, cos i will put it on my web site for my school and later i can think how i do it :D

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 :)

Kings on steeds

12:17 pm on Jan 2, 2010 (gmt 0)

10+ Year Member



Well the code i posted above checks for an entry of both username and password in the database, if it finds one row (using mysql_num_rows()) then you know there username and password where correct, if not you know it was wrong, if you can write the script above, and you "know" mysql you should be able to use the code i sent to work the rest out.

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

noora

1:39 pm on Jan 2, 2010 (gmt 0)

10+ Year Member



Thanks,
I will try to figure it out. I dont care in this point about security or anything else. Cos this code will not anyway go for public use. This is only showing to my school that i can use these forms somehow.. i dont have to be good in it. I understand that there should be much more if i use it in public. And about my knowledge of mysql, i ment i know simple way to create database and make few queries. I was hoping only answer to my question, without making me feel more stupid than i already feel... :D
Im sorry about my english, maybe i make people understand wrong by my sentenses.
i appreciate your help, thanks!