Codeigniter -> Undefined Variable - php

I am unsure as too why I am getting the following errors when trying to pass data through to my html email template -> The PHP errors are coming from the view.
Undefined variable: companyName -> line 9
Undefined variable: firstName -> line 12
Controller:
function _userRegEmail($activateCode,$email,$firstname,$lastname){
$data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
$data['companyEmail'] = $this->core_model->companyDetails()->coreContactEmail;
$data['companyContact'] = $this->core_model->companyDetails()->coreContactName;
$data['firstName'] = $firstname;
$data['lastName'] = $lastname;
$data['email'] = $email;
$data['activateCode'] = $activateCode;
$this->email->from($this->core_model->companyDetails()->coreContactEmail, $this->core_model->companyDetails()->coreCompanyName);
$this->email->to($email);
$this->email->subject($this->core_model->companyDetails()->coreCompanyName 'User Registration Confirmation');
$messageContent= $this->load->view('email_templates/userReg','', TRUE);
$this->email->message($messageContent);
$this->email->send();
echo $this->email->print_debugger();
}
View:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title/>
</head>
<body>
<div class="container" style="width: 600px;height: 100%;margin: 0 auto;font-family: Arial, "MS Trebuchet", sans-serif">
<div class="header" style="width: 100%">
<h1 style="text-align: center;color: #00afd8"><?php echo $companyName; ?></h1>
</div>
<div class="content">
<h2 style="font-size: 15px">Hello <?php echo $firstName; ?></h2>
<p style="margin-left: 15px">Thank you for signing up to Farm Ads.</p>
<p style="margin-left: 15px">Could you please click <a href="<?php base_url(); ?>users/confirm/"<?php $activateCode; ?>>here</a> to activate your account.</p>
<div class="from">
<p class="bold" style="margin-left: 15px;font-weight: bold;font-size: 12px">Regards,</p>
<p style="margin-left: 15px;font-weight: bold;font-size: 12px"><?php $companyContact; ?></p>
</div>
</div>
</div>
</body>
</html>

If you want to use the variables you have set in $data in the view you shouldn't do:
$messageContent= $this->load->view('email_templates/userReg','', TRUE);
But:
$messageContent= $this->load->view('email_templates/userReg', $data, TRUE);
This makes sure you send the variables to the view so they can be used in there like you are trying already.

Related

How to order divs side by side and centered when get datas from database in php and css

How to order divs side by side and centered when get datas from database in php and css ?
php and html codes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/normalize.css">
</head>
<body>
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="cards">
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
</div>
<?php }?>
</body>
</html>
css style codes
body {
background-color:#282828;
}
a{
text-decoration: none;
}
.cards{
text-align: center;
font-size: 0;
}
.card{
margin: 0 10px;
width: 250px;
text-align: left;
display: inline-block;
font-size: medium;
}
.card-img{
width: 250px;
margin-bottom: -5px;
}
.card-title{
background-color: #FFFCF5;
width: 240px;
padding:5px;
margin-bottom: 15px;
color: #282828;
}
.card-title>p>a{
color: #00BFA5;
}
my page looks like this:
but I want to those pictures order side by side
I couldn't that. How could I do?
Thank you
You got .cards inside you while loop, take it out:
<body>
<div class="cards">
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
<?php }?>
</div>
</body>
The reason your code doesnt work, is because .card is inline-block which will place multiple card nexto eachother, but because you look the .cards (note the S) as well, you wrap each item in a div. A div is a block element, which means it'll take up one whole row, the next element will fall below it.
For each row from database you parse, you will have this following output:
`
<div class="cards">
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
</div>
`
So, all you have to do is to have the cotainer outside the while loop, like this:
`
<div class="cards">
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
<?php }?>
</div>
`
I know it's not exactly what you want, but try :
cards { display : flex ; flex-direction : row ; justify-content : space-between }
/ ! \ Doesn't work on IE8 and previous

Can't access the admin dashboard of my locally hosted site [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I bought a code from someone and hosted it locally and it was working very wonderful but my problem is. I opened the admin table in phpmyadmin and got the admin email and encrypted password. But because I don't know what the password was, I tried adding another admin account via the phpmyadmin (still using local host) but I'm still unable to login to the admin dashboard.
Any solution?
<?php require("../includes/config.php");
require_once(ROOT_PATH . "core/class.admin.php");
$login = new ADMIN();
if($login->
is_loggedin() != ""){
$login->
redirect(BASE_URL.'administrator');
}
if(isset($_POST['loginBtn'])){
$username = strip_tags($_POST['userID']);
$password = strip_tags($_POST['password']);
if($login->
doLogin($username, $password)){
$login->
redirect(BASE_URL.'administrator');
}
else{
$error = "Email Address or Password does not match, please try again!";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
Naija Helper</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="http://creativeweb.com.ng" />
<!-- css -->
<link href="<?php echo BASE_URL;
?>
css/bootstrap.min.css" rel="stylesheet" />
<link href="<?php echo BASE_URL;
?>
css/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="<?php echo BASE_URL;
?>
css/jcarousel.css" rel="stylesheet" />
<link href="<?php echo BASE_URL;
?>
css/flexslider.css" rel="stylesheet" />
<link href="<?php echo BASE_URL;
?>
js/owl-carousel/owl.carousel.css" rel="stylesheet">
<link href="<?php echo BASE_URL;
?>
css/style.css" rel="stylesheet" />
<style type="text/css">
.formWrapper {
width: 40%;
margin: auto;
}
#media (max-width: 767px) {
.formWrapper {
width: 70%;
margin: auto;
}
}
#media (max-width: 480px) {
.formWrapper {
width: 90%;
margin: auto;
}
}
</style>
</head>
<div class="featured_content" style="margin: 0px;
">
<div class="formWrapper">
<div align="center" style="margin-bottom: 20px;
">
<a style="padding-bottom: 20px;
" href="<?php echo BASE_URL;
?>
">
<img src="<?php echo BASE_URL;
?>
img/logo.png" alt="logo"/>
</a>
</div>
<div align="center" style="margin-bottom: 10px;
">
<span style="font-size: 28px;
">
Adminstrators only</span>
<br>
<span>
Secure admin access</span>
</div>
<div style="background: #FFF;
padding: 50px 20px 20px;
border-radius: 5px;
">
<?php if(isset($error)) {
?>
<div class="alert alert-danger">
<i class="fa fa-exclamation-triangle">
</i>
<?php echo $error;
?>
! </div>
<?php }
?>
<form id="contact-form" method="post" action="" role="form" novalidate>
<div class="form-group has-feedback">
<label for="email">
Email Address*</label>
<input type="text" class="form-control" id="userID" name="userID" required placeholder="Enter your Email Or Username">
<i class="fa fa-envelope form-control-feedback">
</i>
</div>
<div class="form-group has-feedback">
<label for="password">
Password*</label>
<input type="password" class="form-control" id="password" name="password" required placeholder="Password">
<i class="fa fa-lock form-control-feedback">
</i>
</div>
<br>
<input type="submit" style="width: 100%;
padding: 20px;
border-radius: 5px;
" value="Login" name="loginBtn" class="btn btn-default">
</form>
</div>
<div class="row">
<div class="col-md-6">
<span style="font-size: 12px;
padding-left: 10px;
">
<a style="color: #666;
" href="register">
<i class="fa fa-lock">
</i>
Register</a>
</span>
</div>
<div class="col-md-6" align="right">
<span style="font-size: 12px;
padding-right: 10px;
">
<a style="color: #666;
" href="#">
<i class="fa fa-lock">
</i>
Forgot Password</a>
</span>
</div>
</div>
</div>
</div>
<?php include(ROOT_PATH."includes/footer.php");
?>
Here is the code of a php page named create_hash.php. It contains a function createHash() to create a new password hash and an example for using it.
Steps to follow:
Place the file create_hash.php somewhere in your project. BUT BE AWARE: Remove the file from your project after you create a new password! You can save it - for later use - somewhere else in your file system if you wish, where it can not be run as such;
Read the comments in the file, they are important;
Complete your own password in the example bellow;
Change the createHash() arguments as you wish;
Let the file run. A new password hash will be displayed on the screen;
Place the new created hash in the admin table;
Try to login in the admin dashboard again;
REMOVE THE FILE create_hash.php FROM YOUR PROJECT!
The create_hash.php:
<?php
/**
* Create a password hash.<br/>
*
* The two digit cost parameter is the base-2 logarithm of the iteration count for<br/>
* the underlying Blowfish-based hashing algorithmeter and must be in range 04-31.
*
* #param string $password Password to be hashed.
* #param integer $algo [optional] PASSWORD_DEFAULT|PASSWORD_BCRYPT. Used algorithm.
* #param integer $cost [optional] Default: 10. Base-2 logarithm of the iteration count. Range 04-31.
* return string Hashed password (min. 60 characters long).
*/
function createHash($password, $algo = PASSWORD_BCRYPT, $cost = PASSWORD_BCRYPT_DEFAULT_COST) {
try {
if ($algo != PASSWORD_BCRYPT || $algo != PASSWORD_DEFAULT) {
throw new Exception('Incorrect hashing algorithm!');
}
if ($cost < 4 || $cost > 31) {
throw new Exception(' The hashing cost must be in range 04-31!');
}
} catch (Exception $exc) {
echo $exc->getMessage();
exit();
}
$options = array(
'cost' => $cost,
);
return password_hash($password, $algo, $options);
}
//----------------------------------------------------
// Example of using the hashing function createHash().
// Give a password with at least 8 characters,
// including ciphers, letters - lowercase and
// uppercase, alpha characters (#, $, #, etc).
//----------------------------------------------------
$password = "Lorem#20Ipsum17";
$hash = createHash($password, PASSWORD_BCRYPT, 12);
echo $hash;
//----------------------------------------------------
You have not written anything in action attribute of form element. Submit your form on some page and check the credentials entered by the user with the database.

Display Data in PDF

Why I cant display the data I echo from the database in a PDF file ?
I used DOMPDF to convert my html. Anyone please help.
Here is the PDF result
PDF result image
Here is connection code
<?php
$id = $_GET['id'];
$conn = pg_connect("host=localhost dbname=mydatabase user=postgres password=admin");
if (!$conn) {
echo "An error occurred. cannot connectect to localhost.\n";
exit;
}
$sql = pg_query($conn, "SELECT * FROM mytable WHERE reference_no = $id ");
if (!$sql) {
echo "Error Ariel 7:50 !!!.\n";
}
while ($row = pg_fetch_assoc($sql)) {
$reference_no = $row['reference_no'];
$wo_name = $row['wo_name'];
}
Here is my convertion code:
error_reporting(0);
require_once ('xdompdf/dompdf_config.inc.php');
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno"><?php echo $reference_no;?></div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname"><?php echo $wo_name;?></div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>'
;
$name = date("Ymd").rand().'.pdf';
$reportPDF=createPDF(12, $pdf_content, 'activity_Report', $name );
function createPDF($pdf_userid, $pdf_content, $pdf_For, $filename){
$path='xdompdf/';
/*$rndNumber=rand();
$filename=$pdf_userid.date("Ymd").$rndNumber.'.pdf';*/
$dompdf=new DOMPDF();
$dompdf->load_html($pdf_content);
$dompdf->render();
$output = $dompdf->output();
file_put_contents($path.$filename, $output);
return $filename;
}
echo '<a href="xdompdf/'.$name.'" > Download </a>';
?>
Please Help me how to display the data.
Change $pdf_content to
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno">' . $reference_no . '</div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname">' . $wo_name . '</div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>';
I think you just need to concat your data in $pdf_content :
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno">'.$reference_no.'</div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname">'.$wo_name.'</div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>';

PHP issue with displaying a mySQLi result [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm having a rather confusing issue with a result that will not display. I'm creating a mailshot application and I'm trying to populate the email with the recipients name as well as an advert. The result works fine when I store it for use with the email that it sends to but it wont display inside the email body. Its a little hard to explain but here is the code that I am using. I have removed a lot of the email body as it was pretty large, where the ... are that is where I've take a load out.
<?php require (__DIR__.'/connections/connections.php');
session_start();
if(isset($_SESSION["UserID"])){
}else{
header('Location: login.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AzTecks Staff | Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/coin-slider.css" />
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</head>
<body>
<div class="main">
<div class="header">
<div class="header_resize">
<div class="menu_nav">
<ul>
<li><span>Staff Home</span></li>
<li><span>Register Client</span></li>
<li class="active"><span>Register Applicant</span></li>
<li><span>Add Vacancy</span></li>
<li><span>Logout</span></li>
</ul>
</div>
<div class="logo">
<h1><span>AzTecks</span> <small style=" height: 12px; font-size: 11px;"> We Advise, We Avertise,</small><small style=" height: 12px; font-size: 11px;"> We Guarantee Not To Compromise</small></h1>
</div>
<div class="clr"></div>
<div class="slider">
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
</div>
<div class="content">
<div class="content_resize">
<div class="mainbar" style="margin-top:0px;">
<?php
echo "<div class=\"article\"><h2>Sending emails, please wait...</h2></div><br />";
/*Variables for mail shot query*/
$Keywords = $_SESSION['aKeywords'];
$Lname = $_SESSION['aLname'];
$Fname = $_SESSION['aFname'];
$CurrentJob = $_SESSION['aCurrentJob'];
$DesiredJob = $_SESSION['aDesiredJob'];
$CurrentSalary = $_SESSION['aCurrentSalary'];
$DesiredSalary = $_SESSION['aDesiredSalary'];
$Town = $_SESSION['aTown'];
$Country = $_SESSION['aCountry'];
$QualLevel = $_SESSION['aQualLevel'];
$Languages = $_SESSION['aLanguages'];
$TPC = $_SESSION['aTPC'];
$TechnicalTerms = $_SESSION['aTechnicalTerms'];
$ApplicantDivision = $_SESSION['aApplicantDivision'];
$query = "SELECT * FROM Applicants WHERE (? IS NULL OR CV_Text LIKE ?) AND (? IS NULL OR Applicant_Last_Name LIKE ?) AND (? IS NULL OR Applicant_First_Name LIKE ?) AND (? IS NULL OR Applicant_Current_Job_Title LIKE ?) AND (? IS NULL OR Applicant_Desired_Job_Title LIKE ?) AND (? IS NULL OR Applicant_Current_Salary >= ?) AND (? IS NULL OR Applicant_Desired_Salary >= ?) AND (? IS NULL OR Applicant_Town LIKE ?) AND (? IS NULL OR Applicant_Country LIKE ?) AND (? IS NULL OR Applicant_Qualification_Level LIKE ?) AND (? IS NULL OR Applicant_Languages LIKE ?) AND (? IS NULL OR T_P_C LIKE ?) AND (? IS NULL OR Applicant_Division LIKE ?) AND (? IS NULL OR Technical_Terms LIKE ?)";
$KeywordsW = '%'.$Keywords.'%';
$LnameW = '%'.$Lname.'%';
$FnameW = '%'.$Fname.'%';
$CurrentJobW = '%'.$CurrentJob.'%';
$DesiredJobW = '%'.$DesiredJob.'%';
$TownW = '%'.$Town.'%';
$CountryW = '%'.$Country.'%';
$QualLevelW = '%'.$QualLevel.'%';
$LanguagesW = '%'.$Languages.'%';
$TPCW = '%'.$TPC.'%';
$TechnicalTermsW = '%'.$TechnicalTerms.'%';
$ApplicantDivisionW = '%'.$ApplicantDivision.'%';
$stmt = $con->prepare($query);
$stmt->bind_param("ssssssssssiiiissssssssssssss", $Keywords, $KeywordsW, $Lname, $LnameW, $Fname, $FnameW, $CurrentJob, $CurrentJobW, $DesiredJob, $DesiredJobW, $CurrentSalary, $CurrentSalary, $DesiredSalary, $DesiredSalary, $Town, $TownW, $Country, $CountryW, $QualLevel, $QualLevelW, $Languages, $LanguagesW, $TPC, $TPCW, $ApplicantDivision, $ApplicantDivisionW, $TechnicalTerms, $TechnicalTermsW);
$stmt->execute() or die("Something went wrong, could not search :-(");
$result = $stmt->get_result();
$count = mysqli_num_rows($result);
if ($count == 0) {
$output = 'Sorry, no results found!';
echo $output;
}
else {
while($row = $result->fetch_object()) {
$id = $row->Applicant_ID;
$queryResult = $con->query("SELECT Contact_Email FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']}");
$ContactDetails = $queryResult->fetch_object();
$email = $ContactDetails->Contact_Email;
$firstname = $row->Applicant_First_Name;
$lastname = $row->Applicant_Last_Name;
$mail_body = "<!doctype html>
<html>
...
Hello ".$ContactDetails->Contact_First_Name." ".$ContactDetails->Contact_Last_Name."<br /><br /><br />
Below is a potential applicant for your consideration.<br /><br />".$row->Applicant_Advert."<br /><br />
...</html>";
$subject = $_SESSION['eSubject'];
$headers = "From:natalie#aztecksonline.net\r\nContent-type: text/html\r\n";
$to = $email;
$mail_result = mail($to,$subject,$mail_body,$headers);
}
}
if($mail_result) {
echo "<script>window.alert(\"Mail Shot Sent!\");</script>";
header('location: index.php');
} else {
echo "Something went wrong :-(";
}
?>
</div>
<div class="sidebar">
<div class="searchform">
<form id="formsearch" name="formsearch" method="post" action="#">
<span>
<input name="editbox_search" class="editbox_search" id="editbox_search" maxlength="80" value="Search Applicants" type="text" />
</span>
<input name="button_search" src="images/search.gif" class="button_search" type="image" />
</form>
<br />
<div class="clr"><div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>
</div>
</div>
<div class="clr"></div>
<div class="gadget">
<h2 class="star"><span>Sidebar</span> Menu</h2>
<div class="clr"></div>
<ul class="sb_menu">
<li>Staff Home</li>
<li>Register Client</li>
<li>Register Applicant</li>
<li>Add Vacancy</li>
<li>Logout</li></ul>
</div>
<div class="gadget">
<h2 class="star"><span>Recent Vacancies</span></h2>
<div class="clr"></div>
<ul class="ex_menu">
<?php
if($cat_side_result = $con->query("SELECT Vacancy_ID, Vacancy_Job_Title, Vacancy_Location FROM Vacancies LIMIT 6")) {
if($cat_side_result->num_rows) {
while($cat_side_row = $cat_side_result->fetch_object()) {
echo '<li>'.$cat_side_row->Vacancy_Job_Title.'<br /> In '.$cat_side_row->Vacancy_Location.'</li>';
mysqli_close($con);
}
}
}
?>
</ul>
</div>
</div>
<div class="clr"></div>
</div>
</div>
<div class="fbg">
<div class="fbg_resize">
<div class="col c1">
<h2>Clients Recently Joined</h2>
<img src="images/Small_Company_logo_ABP.jpg" width="75" height="75" alt="" class="gal" /> <img src="images/Jumpahead1.jpg" width="75" height="75" alt="" class="gal" /> <img src="images/Keopple_logo_small.jpg" width="75" height="75" alt="" class="gal" /> <img src="images/Phantom_small.jpg" width="75" height="75" alt="" class="gal" /> <img src="images/graves-capital_small.jpg" width="75" height="75" alt="" class="gal" /> <img src="images/global-financial-logo_small.gif" width="75" height="75" alt="" class="gal" /> </div>
<div class="col c2">
<h2><span>Services</span> Overview</h2>
<p>At AzTecks we are committed to insuring you have total confidentiality, and do not share any data or information without your say so, please read our privacy agreement for more information.</p>
<ul class="fbg_ul">
<li>More about us</li>
<li>Privacy agreement</li>
<li>Contact us</li>
</ul>
</div>
<div class="col c3">
<h2><span>Contact</span> Us</h2>
<p>If you have any querys about us or have any questions please feel free to contact us.</p>
<p class="contact_info"> <span>Address:</span>1 Shaw Street<br />
Worcester , Worcestershire , UK<br />
<span>Postcode:</span> WR1 3QQ<br />
<span>Telephone:</span> 01905 700158<br />
<span>E-mail:</span>info#aztecksonline.net</p>
</div>
<div class="clr"></div>
</div>
</div>
<div class="footer">
<div class="footer_resize">
<p class="lf">© Copyright AzTecks.</p>
<div style="clear:both;"></div>
</div>
</div>
</div>
</body>
</html>
the $email populates fine as it sends the email with no issue but where it says in the email body $ContactDetails->Contact_First_Name, it does not display at all.
Have I done something rather dumb or is there something else wrong?
The query should look like this:
SELECT Contact_Email, Contact_First_Name, Contact_Last_Name FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']}
You forgot to add Contact_First_Name and Contact_Last_Name into it so it wasn't even fetching them.
Start by adding at the top.
error_reporting(E_ALL);
ini_set('display_errors', '1');
And then add a die(); or exit(); before you actually execute any database updates and then check what is the error in the errors shown by php.
Normally this is because of an illegal way of executing the SQL in question. Try it out.
At first, you should write a readable code.
Now it's a really bad spaghetti code with crazy indentation (read about PSRs).
After that, separate your PHP from HTML, and move interaction with database to a different layer.

How to echo value from php to html

how do i echo a value from php to html in a division (div2--a div i created) of a paragraph(p).
for example: i have a value called $greetings and i assign a value of "Welcome" to it
$greetings = "Welcome";
I tried:
`<p>
<?php
$index = "WELCOME";
echo "<div2>$index</div2>";
?>
</p>`
but it doesn't display the value of $greetings--welcome
instead it displays ( $index"; ?> )
HERES MY ENTIRE CODE:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Tech Planet</title>
<link rel="stylesheet" type="text/css" href="style.css">
<img src="logo.gif" alt="logo" width="150" height="50">
<div class ='seachAndProducts'><form action="header.php" method="GET">
<input id="search" type="text" placeholder="Search Tech Planet...">
<input id="submit" type="submit" value="Search">
</form></div>
<div class = 'navAndFooter'><ul>
<li><b>Home</b></li>
<li><b>Products</b></li>
<li><b>About</b></li>
<li><b>Contact us</b></li>
</ul></div>
<img src="cart.jpg" alt="cart" width="40" height="40">
</head>
<body>
<h3><img src="WelcometoTechPlanet.gif" width="250" height="40"></h3>
<h5><div class ='ourAndFeatProductsHeader'>Our Products</div>
<div class='seachAndProducts'>
<div class='ourProductsList'>Audio Systems</div>
<div class='ourProductsList'>Cameras</div>
<div class='ourProductsList'>Laptops</div>
<div class='ourProductsList'>Memory Cards</div>
<div class='ourProductsList'>Monitors</div>
<div class='ourProductsList'>Phones</div>
<div class='ourProductsList'>Televisions</div>
<div class='ourProductsList'>USBs</div>
<div class='ourProductsList'>All Products</div>
</div><div class ='ourAndFeatProductsHeader'>Featured Products</div>
<div2><img src="8wb50.gif" alt="" width="250" height="200"></div2></h5>
<p><?php
$index = "WELCOME";
echo "<h1>$index</h1>";
?></p>
<!-- used &copy because © displays © -->
<div class = 'navAndFooter'>&copy Tech Planet. All Rights Reserved.</div>
</body>
</html>
Here are a few things to note...
Don't put an h1 tag in the p tag; and you are echoing $index, not $greetings.
Try this
<?php
// Pick the one you want.
$greetings = "Welcome";
$index = "WELCOME";
// Pick the one you want
echo "<h1>$index</h1>";
echo "<h1>$greetings</h1>";
?>
Then, make sure you save it as a .php file, and that you are on a web server with php enabled.

Categories