...

View Full Version : login page



kimmyko
05-18-2011, 05:35 AM
<p>Sign In</p>

<form action ="form.php" method="post">

<h2>Members Login</h2>
<br/>
Please sign in with your username and password.
<br/>
email <INPUT type="text" name="email" value="" id="email"/> <BR>
password<INPUT type="password" name="password" value="" id="password"/> <BR>
<br/>
<INPUT type="submit" value="Send"> <INPUT type="reset">


</form>

this is my php page

<html>
<head></head>
<body>

<form = "loginUser.php" action= "Get">

<?php

// connect to db

$connection = mysql_connect("localhost","root","");
if(!$connection)
{
die("database connection falied: ". mysql_error());
}

// select the database

$db_select = mysql_select_db("admin",$connection);
if(!$db_select){
die("Database connection falied ". mysql_error());
}


$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];



// query the database

$qvar = "INSERT INTO login(
email,username,password
) VALUES (
'{$email}','{$username}','{$password}'
)";



$queryDB = mysql_query($qvar,$connection);

// returned data


if(!$queryDB)
{
die("Database query failed: " . mysql_error());
}
else{
echo "Thank you for registering your username <b>". $username. "</b> <br/>your shopping account has been created!<br/>";

echo "<a href='loginUser.php'>Click here to Login</a>";
}


?>

</form>
<body>
</html>

and this is the message im gettiing
Notice: Undefined index: username in G:\webclient\xampp\htdocs\Mywebsite\form.php on line 25
Database query failed: Duplicate entry '' for key 'PRIMARY'

where am i going wrong?

bullant
05-18-2011, 06:16 AM
which is line 25?

Inigoesdr
05-18-2011, 06:33 AM
Your form is incorrect, it should be:

<form action="loginUser.php" method="post">
Also, you are getting that error because you are trying to access a key in an array($_POST in this case), when the key hasn't been defined. You need to at least check to see if the form has been posted with something like

if(!empty($_POST))
{
// your login code
}
Also, be sure to escape user input. Check the stickies for more information.

kimmyko
05-18-2011, 07:12 AM
thank you, it work

Horologe
05-18-2011, 05:45 PM
http://php.net/manual/en/function.mysql-real-escape-string.php
http://us.php.net/htmlentities
or possibly http://us.php.net/manual/en/function.strip-tags.php
and possibly http://www.regular-expressions.info/email.html for good measure.

http://pastebin.com/hZwiw1Nv <- Like this



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum