PDA

View Full Version : register problem


ali_b
07-03-2007, 08:10 PM
hey,

i thought id try and make a register thing.... and suprise suprise i am stuck..

Ive probably done it all wrong.. im still learing lol but heres what i have so far..

the login page:

<?php
require_once("connections/connection.php"); //database connection
session_start();
////////////////// Getting data ///////////////////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
///////////////////////////////////////////////////
if($userid && $password){
///////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users where user_name='$userid' and user_password='$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
//////////////////////////////////////////////////
}
if ($rowAccount){
$_SESSION['id'] = $rowAccount['user_id'];
header("location:welcome.php");
exit;
}elseif ($submitted){
echo "you do not exist, you may not enter!";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="200" border="1">
<tr>
<td width="79" height="23">user ID </td>
<td width="105"><input name="userid" type="text" /></td>

</tr>
<tr>
<td height="23">Password</td>
<td><input name="password" type="text" /></td>

</tr>

<tr>
<td height="46">&nbsp;</td>
<td><input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="Submit" value="Submit" /></td>

</tr>
</table>
<p><a href="register.php">register</a></p>
</form>
</body>
</html>


and the register page:

<?php
require_once("connections/connection.php"); //database connection
////////////////// Getting data ///////////////////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
///////////////////////////////////////////////////
///////////////////////////////////////////////////
if($email && $password) {
///////////////////////////////////////////////////
$query =sprintf("INSERT into users (user_name, user_password) values ('$userid', '$password')");
mysql_query($query)or die(mysql_error());
//////////////////////////////////////////////////
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<table width="283" border="1">
<tr>
<td width="123">email address:</td>
<td width="144"><input name="userid" type="text" id="email" /></td>
</tr>
<tr>
<td>password:</td>
<td><input name="password" type="text" id="password" /></td>
</tr>
<tr>
<td></td>
<td><input name="submitted" type="hidden" id="submitted" value="1" /><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>

</body>
</html>


the register page doesnt come up with any errors but nothing goes into my database :(

cheers for ur help,

Ali


*EDIT: i have sorted it now, just had a couple things that didnt match up*

Mark_W
07-04-2007, 11:12 PM
Youve called the 'userid' field in your form ID 'email'.



edit/ just noticed you sorted it.