Jump to content


Photo

New User Registration using Email as Primary Key


  • Please log in to reply
5 replies to this topic

#1 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 10 July 2006 - 11:11 AM

hi all,

i am very much happy about this forum that on my first post itself, i got the help. Very thank you.

now my second problem is this.I am creating a simple user registration system, in which i am using email as my Primary Key,

Whenever user fiils the form and submit it, i should check for the existence of the emailID, if exists i should tell them, the user ID or email is existing or i have to register them and send a mail to their email id for activation.

the files are

Register.html

<html>
<head><title>New User Registration</title></head>
<form method="POST" action="newUser.php">
<table>
<tr>
<td>
Enter Your Name</td>
<td><input type="text" name="t1"> *</td>
</tr>
<tr>
<td>Enter a valid Email</td>
<td><input type=" text" name="t2"> *</td>
</tr>
<tr>
<td>Company Name</td>
<td><input type=" text" name="t3"> *</td>
</tr>
<tr>
<td>Address1</td>
<td><input type=" text" name="t4"> *</td>
</tr>
<tr>
<td>Address2</td>
<td><input type=" text" name="t5"></td>
</tr>
<tr>
<td>City</td>
<td><input type=" text" name="t6"> *</td>
</tr>
<tr>
<td>State</td>
<td><input type=" text" name="t7"> *</td>
</tr>
<tr>
<td>
Pincode</td>
<td><input type=" text" name="t8"> *</td>
</tr>
<tr>
<td>Phone Number</td>
<td><input type=" text" name="t9"></td>
</tr>
<tr>
<td>Fax</td>
<td><input type=" text" name="t10"></td>
</tr>
<tr>
<td>
<input type="submit" value="Register"></td>
</tr>
</form>
<p><font face="arial" color="Red"> * - Has to be Filled by the user </p>
</html>



newUser.php

<?php include_once('config.php');
if($_POST['submit'])
{
$name = $_POST['t1'];
$email = $_POST['t2'];
$com_name =$_POST['t3'];
$add1 =$_POST['t4'];
$add2 =$_POST['t5'];
$city =$_POST['t6'];
$state =$_POST['t7'];
$pin =$_POST['t8'];
$phone_num =$_POST['t9'];
$fax =$_POST['t10'];
$sql = "insert into temp_customer (cust_name,cust_email,cust_company, cust_add1, cust_add2, cust_city, cust_state,cust_pin, cust_phone, cust_fax) values ('$name','$email','$com_name','$add1','$add2','$city','$state', '$pin','$phone_num','$fax')";
$result = mysql_query($sql)or die('Error in coding'.mysql_errno().mysql_error());
if($result)
{
$msg = 'Your request has been posted. Thanks for registering.After the processing, you will be intimated about your registration.';
$to="mail@shobhacards.com,lngworks@yahoo.com";
$subject="New User Registration Request";
$messg="A User has requsted for the membership.Kindly Check your administration panel for further details";
mail($to,$subject,$messg);

}else {
$msg = "Request is not been processed.Try again later";
}
}
?>
...
<html>
.....
<?php echo $msg ?>


this code works fine for me, but when user enter the same email id, in the newUser.php i am not getting any messages ?

kindly look into this code

cheers
saikiran
saisen76@hotmail.com

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 10 July 2006 - 12:42 PM

from what I can see you aren't checking the database to see if the e-mail address exists. Also why are you using e-mail address as the primary key, you can just use and int as a primary key and just have e-mail address in the table and query that when ever you need to, it will do the same thing, but ne a little neater.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 July 2006 - 12:47 PM

valadate the email address to prompt the user telling them that the email is tacken before inseting the information ok.

$query="select * from users where id=$id";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result){

if($row['email'] > 0) {

echo "Sorry email tacken please use another one cheers!<br><br>

<a href='what_ever_you_called_this_page.php'>Please Try Agin</a>":

exit;

}







Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 July 2006 - 07:56 AM

hi,

Thank u for ur help cmgmyr and redarrow, thats what logically i am wrong that while inserting the data i am not checking whether the email ID exists or not.

One more mistake i did is telling that email is my PKey, it is not the PKey for me, sorry for that.

now, my question is after collecting all the posted data into the newUser.php file, where should i write the query for checking the email ID is existing !!!.

to Redarrow

$query="select * from users where id=$id";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result){

if($row['email'] > 0) {

echo "Sorry email tacken please use another one cheers!



<a href='what_ever_you_called_this_page.php'>Please Try Agin[/url]":

exit;

}



kindly help me out.

if i am not online, you can mail to me also, as this is very urgent.


cheers
saikiran
saisen76@hotmail.com





#5 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 08:42 AM

I'd personally put it before you do anything else with the data. No point doing any processing if the email exists!
$query="select * from users where id=$id";
$result=mysql_query($query);
if(mysql_num_rows($result) > 0){

echo "Sorry email tacken please use another one cheers!
<a href='what_ever_you_called_this_page.php'>Please Try Agin[/url]":exit;

} else {
//insert statements etc
}

I'm not the best coder in the world by a long shot, so this should be subject to change upon other recommendations.

#6 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 July 2006 - 10:10 AM

hi all,

i have got responses but still pretty much confused abt where to check the code for email.

what i did was just copy pasted the code given by chips and now i am getting nothing on my file, when i submit the form.

This is what i did. May be wrong as i am not that much expert in PHP

I convered my form file to a PHP file

reg.php

<?php include_once('config.php');
$sql = "select cust_id from temp_customer";
$result = mysql_query($sql);
$row = mysql_fetch_array($result,MYSQL_BOTH);
$id = $row['cust_id'];
?>

<html>
<head><title>New User Registration</title></head>
<form method="POST" action="newUser.php">
<table>
<tr>
<td>
Enter Your Name</td>
<td><input type="text" name="t1"> *</td>
</tr>
<tr>
<td>Enter a valid Email</td>
<td><input type=" text" name="t2"> *</td>
</tr>
<tr>
<td>Company Name</td>
<td><input type=" text" name="t3"> *</td>
</tr>
<tr>
<td>Address1</td>
<td><input type=" text" name="t4"> *</td>
</tr>
<tr>
<td>Address2</td>
<td><input type=" text" name="t5"></td>
</tr>
<tr>
<td>City</td>
<td><input type=" text" name="t6"> *</td>
</tr>
<tr>
<td>State</td>
<td><input type=" text" name="t7"> *</td>
</tr>
<tr>
<td>
Pincode</td>
<td><input type=" text" name="t8"> *</td>
</tr>
<tr>
<td>Phone Number</td>
<td><input type=" text" name="t9"></td>
</tr>
<tr>
<td>Fax</td>
<td><input type=" text" name="t10"></td>
<input type="hidden" name="cust_id" value="<?php echo $id ;  ?>" />
</tr>
<tr>
<td>
<input type="submit" value="Register"></td>
</tr>
</form>
<p><font face="arial" color="Red"> * - Has to be Filled by the user </p>
</html>


newUser.php has been modified according to Chips.


<?php include_once('config.php');
global $msg1;
$cust_id = $_POST['cust_id'];
$name = $_POST['name'];
$email = $_POST['email'];
$com_name =$_POST['com_name'];
$add1 =$_POST['address1'];
$add2 =$_POST['address2'];
$city =$_POST['city'];
$state =$_POST['state'];
$pin =$_POST['pincode'];
$phone_num =$_POST['phone'];
$fax =$_POST['fax'];
if($_POST['Submit'])
{
$sql = "select * from temp_customer where cust_id='$cust_id'";
echo $sql;
$result=mysql_query($sql);

while($row=mysql_fetch_assoc($result))
{
if($row['cust_email'] > 0){
echo "The E-mail has been already taken ";
//$msg1 = "The E-mail has been already taken ";
}
}
}?>


i am just echoing whether the query is executing. When i tried to insert the same with same email ID, in this case nothing is happening.

It is just echoing the sql and stays quiet.

pls suggest me if i am wrong...can anyone send me the full code they are using for this. that would be very much helpful as i can go through it fully.

thank u for your support

cheers
sai






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users