Hi there,
I have a problem in one of my scripts.
What I want to do is store names and email addresses into a mysql DB, but I have an if statement with a query that checks if the same email address is in the DB already, if it is not, the name and email address will be stored.
My problem is that the select statement does not execute properly,it sets my result variable as having a value in it,when it does not.
I have played around with the syntax near the variable value, thinking it was that, but to no avail.
My insert statement works perfectly...
Please help! I have sat for ever on this problem.
The code I have is as follows:
<?php
$name = array($_POST['nameone'],$_POST['nametwo'],$_POST['namethree'],$_POST['namefour'],$_POST['namefive'],$_POST['namesix'],$_POST['nameseven'],$_POST['nameeight'],$_POST['namenine'],$_POST['nameten']);
$email = array($_POST['emailone'],$_POST['emailtwo'],$_POST['emailthree'],$_POST['emailfour'],$_POST['emailfive'],$_POST['emailsix'],$_POST['emailseven'],$_POST['emaileight'],$_POST['emailnine'],$_POST['emailten']);
$cell = $_POST['cell'];
?>
<html>
<head>
<title>Emails Entered</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if (!$name[0] || !$email[0])
{
echo 'You have not entered any data in the fields, please go back and start at field one. Thank You.';
echo '<br><a href="emailenter.php">Back<a>';
exit;
}
$db = mysql_pconnect('localhost', 'root', '');
if (!$db)
{
echo 'Error connecting to the database';
exit;
}
$count = 0;
for ($i = 0; $i < 11 ; $i++)
{
if ($email[$i])
{
mysql_select_db('emaildb');
$query = "select * from emails where email like ".$email[$i]."";
$result = mysql_query($query);
if (!$result)
{
mysql_select_db('emaildb');
$query = "insert into emails values
(NULL,'".$cell."','".$name[$i]."', '".$email[$i]."')";
$result = mysql_query($query);
$count++;
}
}
if ($i == 10)
{
echo 'You have successfully entered '.$count.' email addresses, Thank You';
exit;
}
}
?>
</body>
</html>
I have a problem in one of my scripts.
What I want to do is store names and email addresses into a mysql DB, but I have an if statement with a query that checks if the same email address is in the DB already, if it is not, the name and email address will be stored.
My problem is that the select statement does not execute properly,it sets my result variable as having a value in it,when it does not.
I have played around with the syntax near the variable value, thinking it was that, but to no avail.
My insert statement works perfectly...
Please help! I have sat for ever on this problem.
The code I have is as follows:
<?php
$name = array($_POST['nameone'],$_POST['nametwo'],$_POST['namethree'],$_POST['namefour'],$_POST['namefive'],$_POST['namesix'],$_POST['nameseven'],$_POST['nameeight'],$_POST['namenine'],$_POST['nameten']);
$email = array($_POST['emailone'],$_POST['emailtwo'],$_POST['emailthree'],$_POST['emailfour'],$_POST['emailfive'],$_POST['emailsix'],$_POST['emailseven'],$_POST['emaileight'],$_POST['emailnine'],$_POST['emailten']);
$cell = $_POST['cell'];
?>
<html>
<head>
<title>Emails Entered</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if (!$name[0] || !$email[0])
{
echo 'You have not entered any data in the fields, please go back and start at field one. Thank You.';
echo '<br><a href="emailenter.php">Back<a>';
exit;
}
$db = mysql_pconnect('localhost', 'root', '');
if (!$db)
{
echo 'Error connecting to the database';
exit;
}
$count = 0;
for ($i = 0; $i < 11 ; $i++)
{
if ($email[$i])
{
mysql_select_db('emaildb');
$query = "select * from emails where email like ".$email[$i]."";
$result = mysql_query($query);
if (!$result)
{
mysql_select_db('emaildb');
$query = "insert into emails values
(NULL,'".$cell."','".$name[$i]."', '".$email[$i]."')";
$result = mysql_query($query);
$count++;
}
}
if ($i == 10)
{
echo 'You have successfully entered '.$count.' email addresses, Thank You';
exit;
}
}
?>
</body>
</html>