Jump to content

New User Registration using Email as Primary Key


saikiran

Recommended Posts

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

[color=red]<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>

[/color]

[color=brown]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 ?>
[/color]

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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;

}






Link to comment
Share on other sites

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

[color=red][quote]$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;

}[/quote][/color]

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



Link to comment
Share on other sites

I'd personally put it before you do anything else with the data. No point doing any processing if the email exists!
[code]
$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
}[/code]

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

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

[color=red]<?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'];
?>[/color]
<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="[color=red]<?php echo $id ;  ?>[/color]" />
</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.


[color=red]<?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 ";
}
}
}?>
[/color]

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.