hello everyone i am currently working on my website. I wanted to make a php script for registering users. So that they may log in, log out, register, and access member only functions.

I found a good tutorial online but since im fairly new to php and have never worked with SQL i dont have a good idea of what i am doing.

In the website below the user says to make a SQL table so we can keep track of all the members. I have gone into my webhosting control panel and have made a new SQL table but i have no way of modfying it with what he says to put in it.

http://www.trap17.com/forums/Php-Simple-Login-Tutorial-t7887.html

Name the table "dbUsers." It will need 4 fields:

[I]Name             Type                 Addition[/I]
id                          int(10)              Primary Key, AUTO_INCREMENT
username            varchar(16)        Unique
password            char(16)          
email                   varchar(25)

Can anyone help me out with this? Im really confused :(

You must be able to edit the fields in the table you've created.
What are you using to create your databases phpmyadmin ?

you have created your table correctly.now you want to input records into that table.first ill tell you the concept of login,logout and register processes.
when a user tries to login to your site you must check that there is a match with the database data and the user input data.if the password and username matches you allow him to login.
there for the first step is you must allow users to register.assume there is a simple html page with a form for that.
(create separate files for code which separated from ####### marks,save files with the given extention)

########form.html########

<html>
<body>
<form action="register.php" method="post">
<input type="text" name="username" id="username">
<input type="password" name="pw" id="pw">
<input type="text" name="fname" id="fname">
<input type="text" name="email" id="email">
<input type="submit">
</form>
</body>
</html>

#######register.php######

<?php
mysql_connect("your_host_name","your_username","your_password");
mysql_select_db("your_database_name");

mysql_query("INSERT INTO dbusers(name,username,password,email) VALUES('$_POST[fname]','$_POST[username]','$_POST[pw]','$_POST[email]')") or die("cannot execute the query");

echo "user registered";

?>

registration process is finished.now you should create a login form.

######loginform.html######

<html>
<body>
<form action="login.php" method="post">
<input type="text" name="username" id="username">
<input type="password" name="pw" id="pw">
<input type="submit">
</form>
</body>
</html>

when you click on the submit button following login script will run

######login.php#######

<?php
mysql_connect("your_host_name","your_username","your_password");
mysql_select_db("your_database_name");

$myusername=$_POST['username'];
$mypassword=$_POST['pw'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$mysql = "SELECT * FROM dbusers WHERE username='$myusername' and password='$mypassword' ";

$result = mysql_query($mysql) or die("cannot execute query");

$count = mysql_num_rows($result);

if($count==1)
{
  session_register('username');
  header("location:home.php"); // put your home page neme here
}

else
echo "login fail";

?>

]

#####logout.php#####

<?php
session_start();
session_destroy();
echo "successfuly logout";
?>

use this code at the top of your home page to obtain session variable

<?php
session_start();
$username = $_SESSION['username'];
?>

now you can use "$username" variable to display username of the logged in user.
ex.

<?php
      echo "you logged in as ".$username;
      ?>

thats all

how can i link to logout from logout script

i want logout script in php

If you're using hyperlink to logout, then direct your link to logout.php

logout:

echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";

this will destroy the session and return to your index.php file.



Logout.php
<?php
session_start();
session_unset();

session_destroy();
// Logged out, return home.
Header("Location: index.php");
?>

can somebody help me i need a compiling site for documents its like a registration site but your filling up documents for a business. that every page has a login/logout. so that if she/he didn't finish the registration he can logout to save and login to continue thank you

please do email thx

how we have to link the logout script with logout link and where it will redirect

can somebody help me i need a compiling site for documents its like a registration site but your filling up documents for a business. that every page has a login/logout. so that if she/he didn't finish the registration he can logout to save and login to continue thank you

And how much are you going to pay for that? :D
And thank you for hijacking the thread.

Now seriously: Start your thread and post what you have and your programming ability level ;)

logout:

echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";

this will destroy the session and return to your index.php file.



Logout.php
<?php
session_start();
session_unset();

session_destroy();
// Logged out, return home.
Header("Location: index.php");
?>

session_unset(); is not necessary as session_destroy(); does it all ;)

i have an error in checklogin.php in $count it says Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given. how can i fix this?

i am geting following error Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.