Richard Korts
asked on
Programming (php, Javascript) not working
I have this code in program 1:
It displays the confirm, I answer yes.
Unless I'm missing something basic (maybe I am), it goes to email_pdf_new.php.
Code for that is this:
I am user where $_SESSION['user'] = 2. The echos do not display, which implies, it does not enter this program.
Why?
Thanks
<!DOCTYPE html>
<html>
<head>
<title>Print Single Form</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<title>Backflow Assembly & Test Report Form</title>
<style>
.nopadding {
padding: 0 !important;
margin: 0 !important;
}
.wrapper {
max-width: 767px;
min-width: 480px;
margin: 0 auto;
}
</style>
<script>
user = <? print $_SESSION['user']; ?>;
fname = "<? print $fname; ?>";
ac = "";
fr = "<? print $fr; ?>";
ems = "<? print $_GET['ems']; ?>";
loc = "<? print $loc; ?>";
function open_pdf_win() {
str = loc + fname;
window.open(str);
}
function ask_email() {
jj = confirm("Email printed form to my email?");
if (jj) {
window.location = "email_pdf_new.php?f=" + fname;
}
window.location = "print_cleanup.php?fr=" + fr + "&ems=Y";
}
</script>
</head>
<body onLoad="open_pdf_win(); ask_email();">
<? if ($_GET['ems'] != "y") {?>
<body onLoad="ask_email();">
<? } ?>
</body>
</html>
It displays the confirm, I answer yes.
Unless I'm missing something basic (maybe I am), it goes to email_pdf_new.php.
Code for that is this:
<?php
//echo "entered email_pdf_new<br>";
// email_pdf.php
session_start();
// use phpmailer
$f = $_GET['f'];
if ($_SESSION['user'] == 2) {
echo "entered email_pdf_new<br>";
echo "file = " . $f . "<br>";
}
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->isSMTP(); // telling the class to use SMTP transport
$body = "";
$mail->SetFrom('noreply@backflowtestreport.com');
$mail->SMTPSecure = $GLOBALS['smtp_security'];
$mail->Port = $GLOBALS['smtp_port'];
$mail->Subject = "Completed form for " . $_SESSION['pn'];
$body = "Attached is the completed form for the subject property";
$mail->AddAddress(trim($_SESSION['email']));
$mail->AddAttachment($f);
$mail->MsgHTML($body);
$mail->AltBody = strip_tags($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
//echo "sent email";
//echo "going to choose_cust_new<br>";
if (isset($_SESSION['narrow'])) {
if ($_SESSION['narrow'] == "yes") {
header("Location: choose_cust_ph.php?prop=" . $_GET['prop']);
exit;
}
} else {
header("Location: choose_cust.php?prop=" . $_GET['prop']);
}
exit;
//echo $loc;
}
?>
I am user where $_SESSION['user'] = 2. The echos do not display, which implies, it does not enter this program.
Why?
Thanks
The "user" variable in your JS does nothing. JS variables are not sent to the server directly, you would need to add them to the query string or use <input type="hidden"> and actually submit a form.
ASKER
Are you referring to the first set of HTML only code, or the php program?
user is not passed in the query string, it is in a php $_SESSION variable.
Thanks
user is not passed in the query string, it is in a php $_SESSION variable.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good points, I'll try something like that.
Thanks
Thanks
"session_start();" is Required at the top of any PHP file that uses $_SESSION variables. I don't see it in 'program 1'. Correction: EVERY PHP files that uses $_SESSION variables.
ASKER
Dave Baldwin,
I copied ONLY the HTML part at the end. session_start(); is up above (you cannot see it).
I may be trying to simplify things too much for you Experts. I probably should have put the full code in.
Richard
I copied ONLY the HTML part at the end. session_start(); is up above (you cannot see it).
I may be trying to simplify things too much for you Experts. I probably should have put the full code in.
Richard
What is working?
ASKER
I had to do a lot of tweaking so there were not 3 windows open at once, but overall, your method worked very well.
Thanks,
Richard
Thanks,
Richard