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
php
add a comment |
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
php
2
You have a;
at the end of thewhile
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
dovar_dump($row);
to see what exactly is in$row
– marvinIsSacul
Nov 19 at 14:08
add a comment |
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
php
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
php
edited Nov 19 at 8:32
asked Nov 19 at 7:37
Gregar GB
93
93
2
You have a;
at the end of thewhile
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
dovar_dump($row);
to see what exactly is in$row
– marvinIsSacul
Nov 19 at 14:08
add a comment |
2
You have a;
at the end of thewhile
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
dovar_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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
You have a
;
at the end of thewhile
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