Check for various emails addresses – PHP

  php

Q(Question):

Hi, I have form which have 10 fields of emails. like below

1. Friend’s Name: Friend’s Email:
2. Friend’s Name: Friend’s Email:
3. Friend’s Name: Friend’s Email:
4. Friend’s Name: Friend’s Email:
5. Friend’s Name: Friend’s Email:
6. Friend’s Name: Friend’s Email:
7. Friend’s Name: Friend’s Email:

each of the above field has an input also. my question is this how i can check if the email address is present on which serial number? would anybody help me my doing this with function or some other method/procedure?

A(Answer):

Hi.

How does the actual HTML look like?

A(Answer):

Hi.

How does the actual HTML look like?

sorry i dont understand ur question? well it is a form. which have two different input fields one is Friends Name and other is Friend’s Email. i wana refer something to my at least 10 friends then how i can check that if the email address is entered at which field.

A(Answer):

I simply mean; can we see the markup for your form?

There are a lot of different ways your form could be set up.
If we know exactly how it looks like we are not forced to guess, which means we can provide much better suggestions.

We really don’t like guessing 🙂

A(Answer):

ok here is the code

[HTML]<form id="referfriend" method="post" style="display:none" action="advertisewithus.php?action=check">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="WHITE" align="center" >
<tr>
<td colspan="4" align="CENTER" height="25" CLASS="bluebox2" ><h3> Refer A Friend</h3></td>
</tr>
<tr class="tableText">
<td align="LEFT">Your Name</td>
<td align="LEFT" > <input name="name" type="text"></td>
<td align="RIGHT">Your Email</td>
<td align="LEFT"><input id="email" name="email" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="LEFT">1. Friend Name</td>
<td align="LEFT"><input name="friendname1" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail1" name="friendemail1" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">2. Friend Name</td>
<td align="LEFT" ><input name="friendname2" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail2" name="friendemail2" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">3. Friend Name</td>
<td align="LEFT"><input name="friendname3" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail3" name="friendemail3" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">4. Friend Name</td>
<td align="LEFT"><input name="friendname4" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail4" name="friendemail4" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">5. Friend Name</td>
<td align="LEFT"><input name="friendname5" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail5" name="friendemail5" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">6. Friend Name</td>
<td align="LEFT"><input name="friendname6" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail6" name="friendemail6" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">7. Friend Name</td>
<td align="LEFT"><input name="friendname7" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail7" name="friendemail7" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">8. Friend Name</td>
<td align="LEFT"><input name="friendname8" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail8" name="friendemail8" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">9. Friend Name</td>
<td align="LEFT"><input name="friendname9" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail9" name="friendemail9" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT">10.Friend Name</td>
<td align="LEFT"><input name="friendname10" type="text"></td>
<td align="RIGHT">Friend Email</td>
<td align="LEFT"><input id="friendemail10" name="friendemail10" type="text"></td>
</tr>
<tr bgcolor="#FFFFFF" class="tableText">
<td align="RIGHT" WIDTH="19%">Body</td>
<td colspan="4" align="CENTER"><textarea name="mailbody" cols="20" rows="7"></textarea></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="4" align="center"><input name="referSubmit" id="" type="submit" value="Submit" valign="middle"></td>
</tr>
</table></form>[/HTML]

A(Answer):

Ok.

If you give several <input> elements the same name, and if that name ends with [], then PHP will read all those elements into an array when they are submitted.
Which means you could add as many of those <input> elements as you want to your form and have your PHP go through all of them with a simple foreach loop.

So, if you were to name all your Name inputs "name[]", and all your Email inputs "email[]", then a loop like this would print the value for each of them once they were submitted:


foreach($_POST['name'] as $_index => $_name)
{
$_email = $_POST['email'][$_index];
echo "$_index - Name: $_name, Email: $_email<br />";
}

You could use the empty and isset functions to eliminate empty rows and only use those who pass your validation.

Also…
Use [code] tags when posting you code examples.
As a full member I expect you to know this by now.
Please keep that in mind in the future.

Thank you.
Moderator

A(Answer):

Thank u for ur help n support i got ur answer i think the empty field can be eliminated using if(!$friendmail=="") then do this. and im sorry posting my reply without code tags. i appologize and sincerely hope that u shall always keep helping me. thank u once again

LEAVE A COMMENT