Jump to content

Register page - script wont add details to mysql table


overidemehra

Recommended Posts

Hi,

 

i was jsut wondering why does not my script allow to add details when i add the username, password and email. Thought it will not allow me to take the same username or email already present in my mysql table. It even goes thorugh when i add all new details , by saying that i have registered properly and i can login. But when i check in my mysql table, no new data is added. How to fix this?

 

i am new to php... learnt over the net....

 

thanks

 

:)

 

<?php

 

$action=$_GET["action"];

 

$uname = $_POST["user"];

$pword = $_POST["pass"];

$email = $_POST["email"];

$vpass = $pword;

 

$user_name = "xxxxx";

$pass_word = "xxxxx";

$dbname="xxxx";

$table = "login";

$server = "xxxx";

 

$c=mysql_connect($server,$user_name, $pass_word, $table) OR DIE ('Unable to connect to database! Please try again later.');

$db_found=mysql_select_db($dbname);

 

 

//if registering, check fields.

if ($action == register) {

 

if (!$uname || !$pword || !$email || !$vpass) {

print "You must fill out all fields.";

 

exit;

}

$dupe1 = mysql_num_rows(mysql_query("SELECT username FROM `$table` WHERE `username` = '$uname'"));

 

if ($dupe1 > 0) {

print "Someone already has that username.";

 

exit;

}

$dupe2 = mysql_num_rows(mysql_query("SELECT email FROM `$table` WHERE `email` ='$email'"));

if ($dupe2 > 0) {

print "Someone already has that email.";

 

exit;

}

 

//check if passwords are the same

if ($pword != $vpass) {

print "The passwords do not match.";

 

exit;

}

//end

//insert

mysql_query("INSERT INTO login (username, email, pass) VALUES ('$uname','$email','$pword')");

 

print "You are now registered. Login.";

}

?>

 

<html>

<body>

 

<form method=post action=register.php?action=register  name=s>

<table>

<tr><td>Username:</td><td><input type=text name=user></td></tr>

<tr><td>Email:</td><td><input type=text name=email></td></tr>

<tr><td>Pass:</td><td><input type=password name=pass></td></tr>

<tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr>

<tr><td colspan=2 align=center><input type=submit value=Register></td></tr>

</table>

</form>

 

 

</body>

</html>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.