php - how to use if and include statement in displaying different types of content











up vote
-1
down vote

favorite












so im currently having a problem on displaying content based on a condition with the if and include statements. I want to ask if this is possible and how because currently my code does not display anything. the code wont show up the file's c



    <?php 
include 'header (2).php'
?>

<center><h1>Welcome</h1></center>

<?php
$username = "";

//check for connection error also
$db = mysqli_connect('localhost', 'root', '', 'dbname') or die (mysqli_connect_error());

// use limit 1 and make sure username is unique column in your table otherwise you will face issue
$query = "SELECT * FROM users WHERE username='$username'";

//check for query error too
$results = mysqli_query($db, $query) or die(mysqli_error($db));

//use assoc for associative array only
$row = mysqli_fetch_assoc($results);

// do numeric comparision
if ($row['grd'] == 7){
include '7.php';
}
if($row['grd'] == 11) {
include '11.php';
}
?>

<?php include 'footer.php'?>


so i tried to implement the code but nothing seems to show. I had to put the full code so it would not be confusing










share|improve this question




















  • 2




    You have a ; at the end of the while line which will mean the value $grd will not have a value (as the loop will finish before it sets the value).
    – Nigel Ren
    Nov 19 at 7:39










  • You have many errors in your code.
    – Oleg Nurutdinov
    Nov 19 at 7:40










  • Although I don't see any password checking here, it may be worth reading about password_hash() before you do anything with it.
    – Nigel Ren
    Nov 19 at 8:02










  • @NigelRen ahhh that makes sense. Oleg Nurudtinov yeah i know im still learning in php
    – Gregar GB
    Nov 19 at 8:09










  • do var_dump($row); to see what exactly is in $row
    – marvinIsSacul
    Nov 19 at 14:08















up vote
-1
down vote

favorite












so im currently having a problem on displaying content based on a condition with the if and include statements. I want to ask if this is possible and how because currently my code does not display anything. the code wont show up the file's c



    <?php 
include 'header (2).php'
?>

<center><h1>Welcome</h1></center>

<?php
$username = "";

//check for connection error also
$db = mysqli_connect('localhost', 'root', '', 'dbname') or die (mysqli_connect_error());

// use limit 1 and make sure username is unique column in your table otherwise you will face issue
$query = "SELECT * FROM users WHERE username='$username'";

//check for query error too
$results = mysqli_query($db, $query) or die(mysqli_error($db));

//use assoc for associative array only
$row = mysqli_fetch_assoc($results);

// do numeric comparision
if ($row['grd'] == 7){
include '7.php';
}
if($row['grd'] == 11) {
include '11.php';
}
?>

<?php include 'footer.php'?>


so i tried to implement the code but nothing seems to show. I had to put the full code so it would not be confusing










share|improve this question




















  • 2




    You have a ; at the end of the while line which will mean the value $grd will not have a value (as the loop will finish before it sets the value).
    – Nigel Ren
    Nov 19 at 7:39










  • You have many errors in your code.
    – Oleg Nurutdinov
    Nov 19 at 7:40










  • Although I don't see any password checking here, it may be worth reading about password_hash() before you do anything with it.
    – Nigel Ren
    Nov 19 at 8:02










  • @NigelRen ahhh that makes sense. Oleg Nurudtinov yeah i know im still learning in php
    – Gregar GB
    Nov 19 at 8:09










  • do var_dump($row); to see what exactly is in $row
    – marvinIsSacul
    Nov 19 at 14:08













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











so im currently having a problem on displaying content based on a condition with the if and include statements. I want to ask if this is possible and how because currently my code does not display anything. the code wont show up the file's c



    <?php 
include 'header (2).php'
?>

<center><h1>Welcome</h1></center>

<?php
$username = "";

//check for connection error also
$db = mysqli_connect('localhost', 'root', '', 'dbname') or die (mysqli_connect_error());

// use limit 1 and make sure username is unique column in your table otherwise you will face issue
$query = "SELECT * FROM users WHERE username='$username'";

//check for query error too
$results = mysqli_query($db, $query) or die(mysqli_error($db));

//use assoc for associative array only
$row = mysqli_fetch_assoc($results);

// do numeric comparision
if ($row['grd'] == 7){
include '7.php';
}
if($row['grd'] == 11) {
include '11.php';
}
?>

<?php include 'footer.php'?>


so i tried to implement the code but nothing seems to show. I had to put the full code so it would not be confusing










share|improve this question















so im currently having a problem on displaying content based on a condition with the if and include statements. I want to ask if this is possible and how because currently my code does not display anything. the code wont show up the file's c



    <?php 
include 'header (2).php'
?>

<center><h1>Welcome</h1></center>

<?php
$username = "";

//check for connection error also
$db = mysqli_connect('localhost', 'root', '', 'dbname') or die (mysqli_connect_error());

// use limit 1 and make sure username is unique column in your table otherwise you will face issue
$query = "SELECT * FROM users WHERE username='$username'";

//check for query error too
$results = mysqli_query($db, $query) or die(mysqli_error($db));

//use assoc for associative array only
$row = mysqli_fetch_assoc($results);

// do numeric comparision
if ($row['grd'] == 7){
include '7.php';
}
if($row['grd'] == 11) {
include '11.php';
}
?>

<?php include 'footer.php'?>


so i tried to implement the code but nothing seems to show. I had to put the full code so it would not be confusing







php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 8:32

























asked Nov 19 at 7:37









Gregar GB

93




93








  • 2




    You have a ; at the end of the while line which will mean the value $grd will not have a value (as the loop will finish before it sets the value).
    – Nigel Ren
    Nov 19 at 7:39










  • You have many errors in your code.
    – Oleg Nurutdinov
    Nov 19 at 7:40










  • Although I don't see any password checking here, it may be worth reading about password_hash() before you do anything with it.
    – Nigel Ren
    Nov 19 at 8:02










  • @NigelRen ahhh that makes sense. Oleg Nurudtinov yeah i know im still learning in php
    – Gregar GB
    Nov 19 at 8:09










  • do var_dump($row); to see what exactly is in $row
    – marvinIsSacul
    Nov 19 at 14:08














  • 2




    You have a ; at the end of the while line which will mean the value $grd will not have a value (as the loop will finish before it sets the value).
    – Nigel Ren
    Nov 19 at 7:39










  • You have many errors in your code.
    – Oleg Nurutdinov
    Nov 19 at 7:40










  • Although I don't see any password checking here, it may be worth reading about password_hash() before you do anything with it.
    – Nigel Ren
    Nov 19 at 8:02










  • @NigelRen ahhh that makes sense. Oleg Nurudtinov yeah i know im still learning in php
    – Gregar GB
    Nov 19 at 8:09










  • do var_dump($row); to see what exactly is in $row
    – marvinIsSacul
    Nov 19 at 14:08








2




2




You have a ; at the end of the while line which will mean the value $grd will not have a value (as the loop will finish before it sets the value).
– Nigel Ren
Nov 19 at 7:39




You have a ; at the end of the while line which will mean the value $grd will not have a value (as the loop will finish before it sets the value).
– Nigel Ren
Nov 19 at 7:39












You have many errors in your code.
– Oleg Nurutdinov
Nov 19 at 7:40




You have many errors in your code.
– Oleg Nurutdinov
Nov 19 at 7:40












Although I don't see any password checking here, it may be worth reading about password_hash() before you do anything with it.
– Nigel Ren
Nov 19 at 8:02




Although I don't see any password checking here, it may be worth reading about password_hash() before you do anything with it.
– Nigel Ren
Nov 19 at 8:02












@NigelRen ahhh that makes sense. Oleg Nurudtinov yeah i know im still learning in php
– Gregar GB
Nov 19 at 8:09




@NigelRen ahhh that makes sense. Oleg Nurudtinov yeah i know im still learning in php
– Gregar GB
Nov 19 at 8:09












do var_dump($row); to see what exactly is in $row
– marvinIsSacul
Nov 19 at 14:08




do var_dump($row); to see what exactly is in $row
– marvinIsSacul
Nov 19 at 14:08

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370193%2fphp-how-to-use-if-and-include-statement-in-displaying-different-types-of-conte%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370193%2fphp-how-to-use-if-and-include-statement-in-displaying-different-types-of-conte%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy