Forum Moderators: coopster
$thirty_days_ago = time()-2592000; // Current unix timestamp minus thirty days
if ($prior_service == "Yes" && $badlead <> 1) {
dbx_connect();
$duplicate = "SELECT * FROM PriorNew WHERE First_Name = '$First_Name' AND Last_Name = '$Last_Name' AND Address = '$Address' AND City = '$City' AND State = '$State' AND Zip_Code = '$Zip_Code' AND Area_Code = '$Area_Code' AND Phone1 ='$Phone1' AND Phone2 = '$Phone2' AND Email = '$Email' AND Confirm_Email = '$Confirm_Email' AND Birth_Month = '$Birth_Month' AND Birth_Day = '$Birth_Day' AND Birth_Year = '$Birth_Year' AND Gender = '$Gender' ";
echo $thirty_days_ago;
$mysql_result=mysql_query($duplicate) or die(mysql_error());
$dupe_rows = mysql_num_rows($mysql_result) or die(mysql_error());
echo $mysql_result;
echo mysql_num_rows($mysql_result);
if ($dupe_rows >= 1)
{
}
else
{
dbx_connect();
$sqlPS = "INSERT INTO PriorNew VALUES ('$null', '$subject', '$First_Name', '$Middle_Name', '$Last_Name', '$Address', '$Address_2', '$City', '$State', '$Zip_Code', '$Zip_Code2', '$Area_Code', '$Phone1', '$Phone2', '$Email', '$Confirm_Email', '$Contact_By_Email', '$Birth_Month', '$Birth_Day', '$Birth_Year', '$Gender', '$Branch_of_Armed_Services', '$Army_MOS', '$Last_Rank', '$Ready_Reserve', '$years', '$obligation', '$Ethnic_BackgroundPrior', '$ETSPRIOR', '$PRIOR_WHY', '$validatekey', '1', '$signup_date', '$SSN')";
$resultPS = mysql_query($sqlPS);
}
}
I appreciate any help I can get.
Are you getting any errors from this? Also, it seems like some of this is unnecessary to do. Wouldn't you agree that you could determine a duplicate based on the email address alone, as they will always be unique? Just an idea to throw around. I don't immediately see any errors as long as you have register globals turned on. Although you haven't escaped the queries, we can sort that out when it works correctly :)
$one = 1;
$two = 3;
if($one == 1) {
if($two == 2) {
echo 'It\'s two!';
} else {
echo 'It\'s not two!';
}
}
Control Structures [us3.php.net]
As for the error, what do you mean by "freezing"? Is your query timing out? How large is this table in terms of rows?
Try turning up your error reporting [php.net] or checking your server's error logs for errors. In the mean time, I'll take one more quick look at your code ;)
if ($prior_service == "Yes" && $badlead <> 1) {
#
dbx_connect();
$_POST = array_map('mysql_real_escape_string',$_POST);
$duplicate = "SELECT * FROM PriorNew WHERE Email = '".mysql_real_escape_string($_POST['Email'])."'";
$mysql_result = mysql_query($duplicate) or die(mysql_error());
$dupe_rows = mysql_num_rows($mysql_result);
echo 'Num of rows: '.$dupe_rows;
#
if(!$dupe_rows)
{
$sqlPS = "INSERT INTO PriorNew VALUES ('".$_POST['null']."', '".$_POST['subject']."', '".$_POST['First_Name']."', '".$_POST['Middle_Name']."', '".$_POST['Last_Name']."', '".$_POST['Address']."', '".$_POST['Address_2']."', '".$_POST['City']."', '".$_POST['State']."', '".$_POST['Zip_Code']."', '".$_POST['Zip_Code2']."', '".$_POST['Area_Code']."', '".$_POST['Phone1']."', '".$_POST['Phone2']."', '".$_POST['Email']."', '".$_POST['Confirm_Email']."', '".$_POST['Contact_By_Email']."', '".$_POST['Birth_Month']."', '".$_POST['Birth_Day']."', '".$_POST['Birth_Year']."', '".$_POST['Gender']."', '".$_POST['Branch_of_Armed_Services']."', '".$_POST['Army_MOS']."', '".$_POST['Last_Rank']."', '".$_POST['Ready_Reserve']."', '".$_POST['years']."', '".$_POST['obligation']."', '".$_POST['Ethnic_BackgroundPrior']."', '".$_POST['ETSPRIOR']."', '".$_POST['PRIOR_WHY']."', '".$_POST['validatekey']."', '1', '".$_POST['signup_date']."', '".$_POST['SSN']."')";
#
$resultPS = mysql_query($sqlPS) or die(mysql_error());
echo ($resultsPS)? 'Added Successfully!':'Failed!';
}
#
}
nested statements are actually perfectly valid
Thanks, but I never said they weren't. I said that:
You can't overlap conditionals
Drunk N Japan,
Your original code has the following (I cut some out for readability):
if ($prior_service == "Yes" && $badlead <> 1) {//-> show info when true
///////////////////////
if ($dupe_rows >= 1){
} else {
//-> your code here
}
///////////////////////} //-> shows white page when this statement is false
As I said earlier, you seem to have some confusion with your conditionals (which eelixduppy has fixed). The reason you were seeing the white screen is because there is no "else" clause to your original "$prior_service == "Yes"" statement because it looks like you mistakenly overlapped (NOT nested) the "$dupe_rows >= 1" conditional. There's nothing wrong with your code, it just has nothing to do if your original conditional is false - hence, blank page. You can see for yourself by adding the else conditional to the end of your original code like:
if ($prior_service == "Yes" && $badlead <> 1) {//-> show info when true
///////////////////////
if ($dupe_rows >= 1){
} else {
//-> your code here
}
///////////////////////} else {
echo "This is a white page";
}
It's nice of eelixduppy to fix your code, but it's better to understand why you are not achieving the desired results yourself.
Correct it to
$dupe_rows = mysql_num_rows($mysql_result)
Don't forget the semicolon at the end ;)
$dupe_rows = mysql_num_rows($mysql_result);
but it's better to understand why you are not achieving the desired results
Most defnitely, I agree! It was my understanding that there was a fatal error in the code which was leading to the blank page, not a logical error. If there were an error, it would probably be from something I fixed in my post, so I was trying to show by example.
I'm glad Michal has well-trained eyes as I definitely didn't catch that! :)
Good luck!
if((all the variables pass verification)){
dbx_connect();//connect to database function
$duplicate="SELECT * From `table` Where var1 = 'var1eqv' AND ...
$dupe_result=mysql_query($duplicate) or die(mysql_error());
$dupe_rows = mysql_num_rows($dupe_result);
if (!$dupe_rows)
{
//insert non duplicate with status as 3
dbx_connect();
$sqlAR = "INSERT INTO table VALUES ('$null','etc',...)";
$resultAR = mysql_query($sqlAR);
}
else
//if duplicate put 99 as status
{
dbx_connect();
$sqlAR = "INSERT INTO table VALUES ('$null','etc',...)";
$resultAR = mysql_query($sqlAR);
}
if((all the variables pass verification)){
dbx_connect();//connect to database function
$duplicate="SELECT * From `table` Where var1 = 'var1eqv' AND ...
$dupe_result=mysql_query($duplicate) or die(mysql_error());
$dupe_rows = mysql_num_rows($dupe_result);
if (!$dupe_rows)
{
//insert non duplicate with status as 3
$sqlAR = "INSERT INTO table VALUES ('$null','etc',...)";
$resultAR = mysql_query($sqlAR);
}//end if non duplicate
else
//if duplicate put 99 as status
{
$sqlAR = "INSERT INTO table VALUES ('$null','etc',...)";
$resultAR = mysql_query($sqlAR);
}//end else if non duplicate
}//end if all vars ok
if now it's only 3 entries, then you've got yourself an answer
Michal
<?
// var1
if ($var1 == "Yes" && $badlead <> 1)
{$dbtable = "table1";}// var2
else if ($var2 == "Yes" && $badlead <> 1)
{$dbtable = "table2";}// var3
else if ($var3 == "Yes" && $badlead <> 1)
{$dbtable = "table3";}//calculate 30 day interval
$thirty_days_ago = time()-2592000; // Current unix timestamp minus thirty days//connect to database
dbx_connect();if ($dbtable == "table3")
{
$duplicate = "SELECT * FROM `$dbtable` WHERE E_MAIL = '$Email' AND entry_date > '$thirty_days_ago' AND (status = '4' OR status = '3')";
$dupe_result=mysql_query($duplicate) or die(mysql_error());
}
else if ($dbtable=="table2")
{
$duplicate = "SELECT * FROM `$dbtable` WHERE Email = '$Email' AND entry_date > '$thirty_days_ago' AND (status = '1' OR status = '2')";
$dupe_result=mysql_query($duplicate) or die(mysql_error());
}
else
{
$duplicate = "SELECT * FROM `$dbtable` WHERE Email = '$Email' AND entry_date > '$thirty_days_ago' AND (status = '4' OR status = '3') ";
$dupe_result=mysql_query($duplicate) or die(mysql_error());
}
$dupe_rows = mysql_num_rows($dupe_result);
if (!$dupe_rows)
{
//initial entry status value
if ($dbtable == "table2")
{$status="1";}
else
{$status = "3";}
}
else
//duplicate status (99)
{$status = "99";}?>