user707165
user707165

Reputation:

PHP download code not working

Could some one please tell me why this bit of code is not working. I want the user to download a file "tokina.pdf" after he has submitted user data, the page redirects to the login page if any field is empty. But the bit of code always starts a download process even if user data is incorrect.

Thank you

<?php


$name = $_POST["name_first"];

$mail = $_POST['email'];    

$number = $_POST['phone_number'];

echo "Name : $name";       
echo '<br>';    
echo "Email-ID : $mail";     
echo '<br>';    
echo "Phone-Number : $number";       
$email_message = "first name: {$name} email is {$mail} number is {$number} ";     
mail('[email protected]', 'Form Response', $email_message);        
if ($mail == "" && $name == "" && $number == "")      
{

header('Location: m1.php'); (redirect to page where user data is collected)
echo "error in submitted data";      
}    
else
{  

//download.php  

//content type  

header('Content-type: application/pdf');         

//open/save dialog box  


header('Content-Disposition: attachment; filename="tokina.pdf"');        

//read from server and write to buffer  

readfile('tokina.pdf');         

}





?>

Upvotes: 2

Views: 335

Answers (1)

c0mm0n
c0mm0n

Reputation: 969

if any field is empty

So it's not AND but OR

if ($mail == "" && $name == "" && $number == "")

shoud be

if ($mail == "" OR $name == "" OR $number == "")

Upvotes: 4

Related Questions