NewStats: 3,264,948 , 8,185,188 topics. Date: Thursday, 12 June 2025 at 10:28 PM 3n2j

6z3e3g

Is Something Wrong With This Code - Programming - Nairaland 3h3l3q

Is Something Wrong With This Code (1954 Views)

(4)

(1) (Go Down)

ebenz01: 1:02pm On Sep 14, 2012
Pls is something wrong with my code?
im trying to avoid multiple email entries, but the code keeps inserting data with multiple emails.
And whenever i put email as unique in my database, it dosent show anything if the data already exist


<?


if($submit)
{

$name=$_POST[name];
$address=$_POST[address];
$email=$_POST[email];
$phone=$_POST[phone];

$conn=mysql_connect('localhost','name','');
$db=mysql_select_db('family_jo151');
$query1="SELECT * FROM bfs_list WHERE email='.mysql_real_escape_string($_POST[email]) .'";
$result=mysql_query($query1)or die(mysql_error());
$p=mysql_fetch_array($result);






if(empty($name))
{
?>
<div align="center">
<p></div>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><font face="Bodoni MT"><b>The &quot;<font color="#FF0000">NAME</font>&quot; Field is empty</b></font></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>
<?
}
elseif(empty($address))
{
?>
<div align="center">
<p></div>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="family%20booster/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><font face="Bodoni MT"><b>The &quot;<font color="#FF0000">ADDRESS</font>&quot; Field is empty</b></font></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>
<?
}
elseif(empty($email))
{
?>
<div align="center">
<p></div>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><font face="Bodoni MT"><b>The &quot;<font color="#FF0000">EMAIL</font>&quot; Field is empty</b></font></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>
<?
}
elseif (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", $email))
{
?>
<div align="center">
<p></div>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><font face="Bradley Hand ITC"><b>Your &quot;<font color="#FF0000">EMAIL</font>&quot;
</b></font><b><font face="Bodoni MT">is not in the correct
format</font></b></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>

<?
}

// THIS IS WHERE I CHECKED FOR MULTIPLE ENTRIES

elseif($email=="$p[mail]"wink
{
?>
<div align="center">
<p></div>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><b><font face="Bodoni MT">You have been previously
ed for <font size="5">BFS</font></font></b></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>
<?
}
elseif(empty($phone))
{
?>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><font face="Bodoni MT"><b>The &quot;<font color="#FF0000">PHONE</font>&quot;
field must not be empty</b></font></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>

<?
}
elseif(!ereg("^([0-9]{9,13})$", $phone))
{
?>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p><font face="Bodoni MT"><b>The &quot;<font color="#FF0000">PHONE</font>&quot;
field value must contain numbers only, and minimum of 9 numbers, maximum
of 13 numbers</b></font></p>
<p><a href="javascript:history.back(-1);">Back</a></p>
<p></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>

<?
}
else
{
$query="INSERT INTO bfs_list VALUES ('$name','$address','$email','$phone','')";
$suxes=mysql_query($query);
if($suxes)
{
?>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p>&nbsp;</p>
<p><b><font face="Bodoni MT">You have been successfully ed
for BFS Summit</font></b></p>
<p><b><font face="Bodoni MT"><a href="http://familybooster.com">
Click Here</a> to Continue</font></b></td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>

<?
}
else
{
?>

<div align="center">
<table cellpadding="0" cellspacing="0" width="779" height="489" background="images/stories/bfs_form_bg.jpg">
<!-- MSTableType="layout" --><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td height="67">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFFF">
<img border="0" src="images/stories/bfs_form_header.jpg" width="439" height="119"><p>&nbsp;</p>
<p>&nbsp;</p>
<p><b><font face="Bodoni MT" color="#FF0000">An error occured while
trying to you</font></b></p>
<p><b><font face="Bodoni MT"><a href="javascript:history.back(-1);">
Click Here</a> to try again</font></b></p>
</td>
<td height="350">&nbsp;</td>
</tr>
<tr>
<td width="143">&nbsp;</td>
<td width="476">&nbsp;</td>
<td height="72" width="160">&nbsp;</td>
</tr>
</table></div>


<?
}
}
}
?>
lordZOUGA(m): 8:10pm On Sep 14, 2012
ask your debugger
Kslib(m): 8:23pm On Sep 14, 2012
lordZOUGA: ask your debugger
Am not a programmer,but wasn't the debugger created by someone...
Javanian: 8:28pm On Sep 14, 2012
lol grin
lordZOUGA(m): 10:05pm On Sep 14, 2012
Kslib:
Am not a programmer,but wasn't the debugger created by someone...
you are definitely not a programmer
Kslib(m): 10:10pm On Sep 14, 2012
lordZOUGA: @kslib
you really got me
Kslib(m): 10:11pm On Sep 14, 2012
Now watch me program ur comments...
lordZOUGA: @kslib
you really got me
i told ya!!!
VictorAkujobi: 7:49pm On Sep 16, 2012
Do you have "on duplicate" in your query? If you make the fields unique, you need to add in "<initial query>on duplicate $this = $that, $thisOtherThing = $thatOtherThing";
VictorAkujobi: 8:07pm On Sep 16, 2012
Oh and escape the variables in your query or better yet, use mysqli with prepared statements or even better yet, PDO. You don't want someone stealing your data, or worse, dropping your DB tables
ebenz01: 8:28am On Sep 26, 2012
tnks for ur contribution. I finally got a way round it
Re: Is Something Wrong With This Code by Nobody: 8:32am On Oct 04, 2012
I THINK YOU SHOULD GO TO YOUR DATABASE BACKEND AND TWEEK THE EMAIL TABLE TO UNIQUE,OR BETTER STILL CREATE A QUERY THAT CHECK AND REPLY EXISTING EMAIL.
Re: Is Something Wrong With This Code by Nobody: 9:04am On Oct 04, 2012
build a logic to check the database if email exists, if it exists, tell the to get a life
if it doesn't, insert it.

(1) (Reply)

How Important Is Data Structures And Algorithm To Pro Developers

(Go Up)

Sections: How To . 46
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or s on Nairaland.