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.
Related
Hello guys
I have a db with guides that in admin mode can be edited. I have just remade the input area and all is good except when logged in as admin i cant update guides, it simply creates a new guide instead of simply updating.
Please be gentle with me as i am a beginner in the coding world, + i would love some fresh eyes on this :) thank you very much
my dashboard code
<?php include("header.php"); ?>
<?php
if(!isset($_SESSION['isLogin']) && $_SESSION['isLogin'] != "YES"){
die("<script> window.location = 'login.php' </script>");
}
$error=false;
$success=false;
if(isset($_GET) && !empty($_GET)) {
$id = base64_decode($_GET['id']);
$user_id = $_SESSION['userInfo']['id'];
$selectSql = "SELECT * FROM guides WHERE 1 = 1 AND user_id = " . $user_id . " AND id = " . $id;
$result = $conn->query($selectSql);
$id = 0;
$title = $step2 = $step3 = $step4 = $step5 = $step6 = $step7 = $step8 = $step9 = '';
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$title = $row['title'];
$step2 = $row['step2'];
$step3 = $row['step3'];
$step4 = $row['step4'];
$step5 = $row['step5'];
$step6 = $row['step6'];
$step7 = $row['step7'];
$step8 = $row['step8'];
$step9 = $row['step9'];
}
}
}
if(isset($_POST) && !empty($_POST)){
$user_id = $_SESSION['userInfo']['id'];
if($_POST['id']){
$sqlInsert = 'UPDATE guides SET title = "'.htmlentities($_POST["title"]).'", step2 = "'.htmlentities($_POST["step2"]).'", step3 = "'.htmlentities($_POST["step3"]).'", step4 = "'.htmlentities($_POST["step4"]).'", step5 = "'.htmlentities($_POST["step5"]).'", step6 = "'.htmlentities($_POST["step6"]).'", step7 = "'.htmlentities($_POST["step7"]).'", step8 = "'.htmlentities($_POST["step8"]).'", step9 = "'.htmlentities($_POST["step9"]).'" WHERE id = ' . $_POST['id'] . ' AND user_id = ' . $_SESSION['userInfo']['id'];
}else{
$sqlInsert = 'INSERT INTO guides(user_id, title, step2, step3, step4, step5, step6, step7, step8, step9)VALUES ("' .$user_id. '", "'.htmlentities($_POST["title"]).'", "'.htmlentities($_POST["step2"]).'", "'.htmlentities($_POST["step3"]).'", "'.htmlentities($_POST["step4"]).'", "'.htmlentities($_POST["step5"]).'", "'.htmlentities($_POST["step6"]).'", "'.htmlentities($_POST["step7"]).'", "'.htmlentities($_POST["step8"]).'", "'.htmlentities($_POST["step9"]).'")';
}
if ($conn->query($sqlInsert) === TRUE) {
if($_POST['id']){
$success = "Your guide has been updated successfully!";
}else{
$success = "Your guide has been added successfully!";
}
$_SESSION['success'] = $success;
header("Location: dashboard.php");
}else{
$error[] = "Error Message: ".$conn->error;
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Guideory - share your knowledge</title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-
scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Guideory - share your knowledge" />
<!--web-fonts-->
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<!--web-fonts-->
</head>
<body>
<div class="header">
</div>
<!---header--->
<!---main--->
<div class="main">
<div class="main-section">
<div class="login-form">
<h2>Share a piece of your knowledge</h2>
<br>
<h4>You can create up to 8 steps, not including the title.
Atleast one step is required. When writing your guide, remember that other
people have to be able to read it, so be as specific as possible.</h4>
<form role="form" method="post">
<div id="step-1">
<ul>
<li class="text-info" id="title">Title:</li>
<li><input type="text" value="<?php echo $title;
?>" name="title" id="title" placeholder="Enter the title for your guide here"
required></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info" id="step2">Step 1:</li>
<li><textarea name="step2" id="step2"
placeholder="Enter the description for step 1 here" required><?php echo
$step2; ?></textarea></li>
<div class="clear"></div>
</ul>
<br>
<ul>
<li class="text-info">Step 2:</li>
<li><textarea name="step3" placeholder="Enter the
description for step 2 here"><?php echo $step3; ?></textarea></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info">Step 3:</li>
<li><textarea name="step4" placeholder="Enter the
description for step 3 here"><?php echo $step4; ?></textarea></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info">Step 4:</li>
<li><textarea name="step5" placeholder="Enter the
description for step 4 here"><?php echo $step5; ?></textarea></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info">Step 5:</li>
<li><textarea name="step6" placeholder="Enter the
description for step 5 here"><?php echo $step6; ?></textarea></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info">Step 6:</li>
<li><textarea name="step7" placeholder="Enter the
description for step 6 here"><?php echo $step7; ?></textarea></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info">Step 7:</li>
<li><textarea name="step8" placeholder="Enter the
description for step 7 here"><?php echo $step8; ?></textarea></li>
<div class="clear"></div>
</ul>
<ul>
<li class="text-info">Step 8:</li>
<li><textarea name="step9" placeholder="Enter the
description for step 8 here"><?php echo $step9; ?></textarea></li>
<div class="clear"></div>
</ul>
<input type="submit" value="Create guide">
</form>
</div>
</div>
</div>
</body>
</html>
There is no input with name id so $_POST['id'] doesn't exist and that's why there's an insert instead of update.
And some extra hints
!isset($_SESSION['isLogin']) && $_SESSION['isLogin'] != "YES"
You probably want isset($_SESSION['isLogin']) here since when the variable is not set it can never be YES
isset($_GET) && !empty($_GET)
You can drop isset here and only use empty.
while ($row = $result->fetch_assoc()) {
Only the last row is stored in those variables, since you are overwriting them.
<?php
include ("db.php");
session_start();
$user = $_SESSION["user"];
if (isset($_POST["submit"])) {
$target_dir = "pics/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
//check if there was an error
if ($uploadOk == 0) {
echo "The file couldnt be upload, please try again";
} else {
if (move_uploaded_file($_FILES["img"]["tmp_name"], $target_file)) {
echo "The file has been uploaded";
} else {
echo "Sorry there was a error";
}
}
$img = $_FILES['img']['name'];
$title = $_POST["cardname"];
$info = $_POST["description"];
$insta = $_POST["insta"];
$snap = $_POST["snap"];
$code = $_POST["code"];
$bg = $_POST["bg"];
$discord = $_POST["discord"];
$sql = "SELECT * FROM cards WHERE code = '".$code."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Please pick a new id, that one is already taken";
} else {
$sql = "INSERT INTO cards (title, user, link, code, image, description, likes, snap, insta, yt, bg, discord)
VALUES ('$title', '$user', '$link', '$code', '$img', '$info', '0', '$snap', '$insta', '$user', '$bg', '$discord')";
if ($conn->query($sql) === TRUE) {
echo "New card created!";
} else {
echo "There was an error";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="main.css">
<title>Personal cards for your social media or business | SocialCard</title>
</head>
<body>
<style>
.white {
color: white !important;
}
</style>
<div class="jumbotron">
<div class="container text-center">
<h1 class="big">Cards</h1><br>
<?php
$sql3 = "SELECT * FROM cards WHERE user = '$user'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0) {
//output cards
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $img; ?>">
</div>
</div>
</div>
</div>
<?php
}
}
?>
<br>
<?php echo $_SESSION["user"]; ?>
<hr>
<div class="card">
<div class="card-body text-center">
<h4>Card Name:</h4>
<form action="" enctype="multipart/form-data" method="post">
<br>
<input type="text" name="cardname">
<br>
<br>
<h4>Profile Image:</h4>
<input type="file" name="img">
<br>
<br>
<h4>Short info:</h4>
<input type="text" name="description">
<br>
<br>
<h4>Instagram link:</h4>
<br>
<input type="text" name="insta">
<br>
<br>
<h4>Snapchat link:</h4>
<br>
<input type="text" name="snap">
<br>
<br>
<h4>Discord Tag:</h4>
<br>
<input type="text" name="discord">
<br>
<br>
<h4>Background Color:</h4>
<br>
<input type="text" name="bg" placeholder="#hexcode">
<br>
<br>
<h4>Unique Id:</h4>
<br>
<input type="text" placeholder="Create One :), remember it" name="code" required>
<br>
<br>
<button type="submit" name="submit" class="btn btn-lg btn-primary">Create Card</button>
<p>To get to your card go to: social-card.pw/view.php?code=youruniqueid</p>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="card bg-dark">
<div class="card-content white">
<h1 class="text-center font1">Purchase Premium</h1>
<p class="text-center">Nothing here yet</p>
<script data-cfasync='false' type='text/javascript' src='//p258030.clksite.com/adServe/banners?tid=258030_546328_0&type=footer&size=37'></script>
</div>
</div>
</div>
</body>
</html>
This is my current php and html code, I must of made a small error because I everytime I go to view it the only thing that shows on my screen is the jumbotron at the top with the test "card" inside it, please help me! I'm sure its just a small error that I cant find out the answer to.
Im assuming its the php code, if anyone can help that would be great.
Assuming that your query is actually retrieving the cards, the display isn't fetching the image from the returned result...
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $img; ?>">
</div>
</div>
</div>
</div>
<?php
}
Using $img for the image isn't using the data from $row.
You should have something like...
echo $row['image'];
I'm also unsure if there is an extra </div> in the loop, you may need to move the last </div> outside the loop, but check this with the generated source.
Place the session_start() at the first line of page, i.e.:
session_start();
include ("db.php");
session_start(); must be started before any other line or operation.
<div class="jumbotron">
<div class="container text-center">
<h1 class="big">Cards</h1><br>
<?php
$sql3 = "SELECT * FROM cards WHERE user = '$user'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0) {
//output cards
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $row['image']; ?>">
</div>
</div>
</div>
<?php
}
}
?>
Check all closing div
Hi all I don't know if anyone will or can help me but for the last week or so I have been trying to make up a profile page setup on my website but I can not get the pages to register any echo's or jest even php (It gives me blank pages and or tell me an error 500 server error)
I have set up my website with a static page for my logo, navbar and footer and using a include line to get the content on the pages. (I hope that makes sense).
if I put any form of php into the content pages it give me errors of 500 server error and or the pages just turns completely white.
Is there a specific way to show SQL content and or any PHP with this set up? if anyone knows any tutorials or could lend a hand that would be amazing (Any help will be placed onto the website on the Credits page).
Here is the static page code:
<?php require '../connection/conn.php'; ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="../css/Master.css" />
<link rel="stylesheet" type="text/css" href="../css/Menu.css" />
<link rel="stylesheet" type="text/css" href="../css/AboutImages.css" />
<link rel="stylesheet" type="text/css" href="../css/Form.css" />
</head>
<body>
<div class="container">
<div class="header">
<div id="logindata"></div>
</div>
<div class="menu">
<nav>
<ul class="cssmenu">
<li>Home</li>
<li>About Us</li>
<li>Videos</li>
<li>Contact Us</li>
<li>Forum</li>
<li></li>
<li>My Account</li>
<li>Logout</li>
</ul>
</nav>
</div>
<div class="content">
<?php echo $content;?>
</div>
<div class="footer">
<p>All Rights Reserved, LPGamers.com, Created And Built by Robert Prince & Amber Milton-White</p> Credits Page
</div>
</div>
</body>
</html>
And the content page:
<?php
$title = 'LPGamers -- Personal Account';
$content = '
<div id="formbox">
<form action="" method="GET">
<p>Search for you friends here !</p>
<input type="text" class="tfield">
<input type="submit" class="button">
</form>
</div>
<div class="ppicture">
<img src="" />
</div>
<div class="pd">
</br>
<p class="pdp">
Account id: # $userid
</p>
</br>
<p class="pdp">
Name:
</p>
</br>
<p class="pdp">
Age:
</p>
</br>
<p class="pdp">
Your Email:
</p>
</br>
<p class="pdp">
Your Bio:
</p>
</div>
';
include ("Site_View.php");
?>
If this help any more Thanks in advance
Edited the answer, it looks like some content of the original post was not displayed initially.
Do not put the form in the PHP code, it is not needed. You want to put the result probably there.
If you want to get data from SQL in PHP do the following:
Prerequisite: setup the php.ini to use whatever database you need, like:
extension=php_sqlsrv_56_nts.dll
Define a database connection
$serverName = "myserver";
$usr="mySQLuser";
$pwd="mySQLpass";
$db="mydatabase";
$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) {
die( print_r( sqlsrv_errors(), true));
}
Use the SQL connection to retrieve data.
$sql = "Select name from Users where users.name = " . $myparam;
note: the example above is vulnerable to SQL injection, but it is an easy start for coding, you can fix this later when you are familiar with it. Also you need to give a value to $myparam first.
Then:
$stmt = sqlsrv_query($conn, $sql);
sqlsrv_next_result($stmt);
sqlsrv_fetch($stmt);
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
Now you can use the data when you want, like this:
<?php
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$returnedName = $row['name'];
echo $returnedName;
}
?>
I am running a localhost website using Flask and python. I have some php files that I want to run when the users click a button. Problem is that Flask isn't recognizing the PHP file as PHP code and the code is showing up as text on the webpage. It's showing the text of all the echo statements, but the words in those statements correspond to variable in the code that allow the user to login and logout of the website. What do I do?
Python Code:
#app.route('/example.php')
def phpexample():
return render_template('example.php')
This shows a html page with text resulting from the echo statements.
The PHP code (example.php):
<?php
require ('steamauth/steamauth.php');
?>
<html>
<head>
<title>Eliminate Phishers! Join Steap now</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/init.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-wide.css" />
</noscript>
<!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]-->
</head>
<body>
<!-- Header -->
<div id="header">
<span class="logo icon fa-paper-plane-o"></span>
<h1>Welcome. This is Steap</h1>
<p>A website designed to help eliminate phishers
<br />
and hackers on Steam.</p>
</div>
<!-- Main -->
<div id="main">
<header class="major container small">
<h3>
<?php
if(!isset($_SESSION['steamid'])) {
echo "welcome guest! <br />\n please login ";
steamlogin(); //login button
} else {
include ('steamauth/userInfo.php');
$url = $steamprofile['profileurl'];
if ($steamprofile['personastate'] == 0) {
$state = '<span style="color:#616161";>(Offline)</span>';
$picture = '<span style="color:#616161";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 1) {
$state = '<span style="color:#006EFF";>(Online)</span>';
$picture = '<span style="border: 10px dotted #006EFF;"><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 2) {
$state = '<span style="color:#006EFF";>(Busy)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 3) {
$state = '<span style="color:#006EFF";>(Away)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 4) {
$state = '<span style="color:#006EFF";>(Snooze)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 5) {
$state = '<span style="color:#006EFF";>(Looking to Trade)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 6) {
$state = '<span style="color:#006EFF";>(Looking to Play)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
}
//Protected content
echo "Welcome back" . "</br> </br>" . $picture ."</br>". $steamprofile['personaname'] . "</br>" .$state . "</br>". "Steam ID: ". $steamprofile['steamid'] . "</br>";
echo 'Steam Profile' . "</br> </br>" . "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>"; // Display their avatar!
}
?>
</h3>
</header>
<footer class="major container small">
<ul class="actions">
<li>Get Phishers</li>
</ul>
</footer>
</div>
<!-- Footer -->
<div id="footer">
<div class="container small">
<header class="major last">
<h2>Questions or comments?</h2>
</header>
<p>Program not working? Not detecting the phishers properly? <br \> Send us a message. We'll be sure to back to you as soon as possible.</p>
<form method="post" action="#">
<div class="row collapse-at-2">
<div class="6u">
<input type="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="email" name="email" placeholder="Email" />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li><input type="submit" value="Send Message" /></li>
</ul>
</div>
</div>
</form>
<ul class="icons">
<li><span class="label">Twitter</span></li>
<li><span class="label">Facebook</span></li>
<li><span class="label">Instagram</span></li>
<li><span class="label">Github</span></li>
<li><span class="label">Dribbble</span></li>
</ul>
<ul class="copyright">
<li>© Steap 2014 All rights reserved.</li><li>Design: HTML5 UP</li>
</ul>
</div>
</div>
</body>
</html>
Maybe you should run php server (such as Apache or another) on other port (such as 8080) and when you call any php file, make request from your flask server to php server. And result getting from php server show with flask server. I hope, you can find the way how to send request from flask to other server.
render_template() isn't support PHP.
You can use subprocess to run PHP script:
import subprocess as sp
#app.route('/example.php')
def phpexample():
out = sp.run(["php", "example.php"], stdout=sp.PIPE)
return out.stdout
Flask is not compatible with php. So it can't read php code.
Have you considered using JQuery Ajax?
Here's an example:
You have a file called get_name.php witch contains:
<?php echo "Hello, my name is John"; ?>
Using Jquery ajax function I call the get_name.php
$.ajax({
url : 'get_name.php',
success : function(data) {
console.log(data);
}
});
The output in the console would be:
Hello, my name is John
So, with the returned data you can do whatever you want.
I'm currently learning PHP and am creating a small CMS feature that includes a login area. I have used the code below which includes an include header file that contains the doctype/head info and the opening tag. It also includes the header content. I also have a connection file for connecting to the db.
My header include code is:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title><?php echo $pagetitle ?></title>
<link rel="stylesheet" href="../stylesheets/foundation.css">
<link rel="stylesheet" href="../stylesheets/app.css">
<style>#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800); #import url (http://fonts.googleapis.com/css?family=Kreon:100,200,300,400);</style>
<script src="../javascripts/modernizr.foundation.js"></script>
</head>
<body>
<div class="subHeader">
<div class="row">
<div class="four columns logo">
<img src="../images/logo.png" alt="logo" />
</div>
<div class="eight columns navigation right">
<ul class="navigationMain">
<li class="<?php if($navcurrent == "home"){echo "navigationActive";} ?>">Home</li>
<li class="<?php if($navcurrent == "services"){echo "navigationActive";} ?>">Services</li>
<li class="<?php if($navcurrent == "work"){echo "navigationActive";} ?>">Recent Work</li>
<li class="<?php if($navcurrent == "about"){echo "navigationActive";} ?>">About</li>
<li class="<?php if($navcurrent == "contact"){echo "navigationActive";} ?>">Contact</li>
</ul>
</div>
<div class="twelve columns titlesection">
<h2><?php echo $headTitle ?></h2>
<h4><?php echo $headsubTitle ?></h4>
</div>
</div><!--End Feature Row-->
</div><!--End Feature-->
<div class="underbar">
<div class="bordertriangle"></div>
<div class="row">
<div class="eight columns"> </div>
<div class="three columns right socialcontainer">
<ul class="socialicons">
<li><a><img id="linkedinIcon" src="../images/socialli.png" alt="linkedin icon" /></a></li>
<li><a><img id="twitterIcon" src="../images/socialtw.png" alt="twitter icon" /></a></li>
<li><a><img id="facebookIcon" src="../images/socialfb.png" alt="facebook icon" /></a></li>
</ul>
</div>
</div>
When I open the admin page, the username password form, header and footer appear as they should. If I test the errors, they return as they should. However, when I successfully log in using a valid username and password, no content appears except the what is included in the header file. Can anyone point me in the direction of what i might be doing wrong? Any help would be much appreciated. I am a relative noob to PHP...
<?php
$pagetitle = "Admin";
$navcurrent = "home";
$headTitle = "ADMIN AREA";
$headsubTitle = "SITE ADMINISTRATION AREA";
include_once('../includes/connection.php');
include_once('../includes/headeradmin.php');
if (isset($_SESSION['logged_in'])) {
echo('Successfully Logged In');
} else {
if (isset($_POST['username'], $_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) or empty($password)){
$error = 'An Error Has Occurred - All Fields Are Required';
}
else{
$query = $pdo->prepare('SELECT * FROM users WHERE user_name = ? AND user_password = ?');
$query->bindValue(1, $username);
$query->bindValue(2, $password);
$query->execute();
$num = $query->rowCount();
if ($num == 1) {
$_SESSION['logged_in'] = true;
header('location: index.php');
exit();
}
else{
$error = 'The username/password you entered was incorrect - Please try again';
}
}
}
?>
<div class="row">
<div class="four columns centered">
<?php if (isset($error)) { ?>
<h5 style="color: #e63333;"><?php echo $error; ?></h5>
<br />
<br />
<?php } ?>
<form action="index.php" method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Login" />
</form>
</div>
</div>
You can't use the header('location: index.php'); line if you've already output content (i.e - html code) to the browser when you included the header in this line include_once('../includes/headeradmin.php');
read the documentation of header - Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP
you need to redirect the user with the header() function before you output the head html of the admin page