MySQLi Query Does not working | Blank PHP Page
I am learning PHP. I am trying one simple mysqli query. I have checked query manually in phpmyadmin and its working fine but in PHP page its not responding. Its not giving any error to. Its appear just blank page. I have checked my db connection and its working fine. I do not know what is issue in it. let me know if anyone can help me for solve it.
My full PHP file is like below
<?php
error_reporting(E_ALL);
include_once("includes/connection.php");
$input = "hello";
$sql = "SELECT answer FROM faq WHERE question = 'hello' ORDER BY id DESC LIMIT 1";
$result = mysqli_query($mysqli,$sql);
if ($result !== false) {
$value = mysqli_fetch_field($result);
echo $value;
} else {
echo "errors";
}
?>
My connection file is like below
<?php
error_reporting(0);
ob_start();
session_start();
header("Content-Type: text/html;charset=UTF-8");
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '');
DEFINE ('DB_HOST', 'localhost'); //host name depends on server
DEFINE ('DB_NAME', 'test');
$mysqli =mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mysqli_set_charset($mysqli,"utf8mb4");
mysqli_query($mysqli,"SET NAMES 'utf8mb4'");
?>
Thanks
php mysql mysqli
add a comment |
I am learning PHP. I am trying one simple mysqli query. I have checked query manually in phpmyadmin and its working fine but in PHP page its not responding. Its not giving any error to. Its appear just blank page. I have checked my db connection and its working fine. I do not know what is issue in it. let me know if anyone can help me for solve it.
My full PHP file is like below
<?php
error_reporting(E_ALL);
include_once("includes/connection.php");
$input = "hello";
$sql = "SELECT answer FROM faq WHERE question = 'hello' ORDER BY id DESC LIMIT 1";
$result = mysqli_query($mysqli,$sql);
if ($result !== false) {
$value = mysqli_fetch_field($result);
echo $value;
} else {
echo "errors";
}
?>
My connection file is like below
<?php
error_reporting(0);
ob_start();
session_start();
header("Content-Type: text/html;charset=UTF-8");
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '');
DEFINE ('DB_HOST', 'localhost'); //host name depends on server
DEFINE ('DB_NAME', 'test');
$mysqli =mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mysqli_set_charset($mysqli,"utf8mb4");
mysqli_query($mysqli,"SET NAMES 'utf8mb4'");
?>
Thanks
php mysql mysqli
If connection is working then check query again, if this query really fetching any data for you.
– Prashant Deshmukh.....
Nov 21 '18 at 5:58
Try echo "Value => ".$value; instead of echo $value; It will be able to detect the blank value, if any.
– ChintanThummar
Nov 21 '18 at 5:59
@ChintanThummar its still blank page
– Mira
Nov 21 '18 at 6:05
@PrashantDeshmukh.....I have double checked and its working fine in phpmyadmin
– Mira
Nov 21 '18 at 6:06
check if the condition comes to if {} or else{} by puting exit; within if and else on the start like echo 'test'; exit; and echo 'test1' exit; Or you can add die() in query to check
– Chris shi
Nov 21 '18 at 6:48
add a comment |
I am learning PHP. I am trying one simple mysqli query. I have checked query manually in phpmyadmin and its working fine but in PHP page its not responding. Its not giving any error to. Its appear just blank page. I have checked my db connection and its working fine. I do not know what is issue in it. let me know if anyone can help me for solve it.
My full PHP file is like below
<?php
error_reporting(E_ALL);
include_once("includes/connection.php");
$input = "hello";
$sql = "SELECT answer FROM faq WHERE question = 'hello' ORDER BY id DESC LIMIT 1";
$result = mysqli_query($mysqli,$sql);
if ($result !== false) {
$value = mysqli_fetch_field($result);
echo $value;
} else {
echo "errors";
}
?>
My connection file is like below
<?php
error_reporting(0);
ob_start();
session_start();
header("Content-Type: text/html;charset=UTF-8");
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '');
DEFINE ('DB_HOST', 'localhost'); //host name depends on server
DEFINE ('DB_NAME', 'test');
$mysqli =mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mysqli_set_charset($mysqli,"utf8mb4");
mysqli_query($mysqli,"SET NAMES 'utf8mb4'");
?>
Thanks
php mysql mysqli
I am learning PHP. I am trying one simple mysqli query. I have checked query manually in phpmyadmin and its working fine but in PHP page its not responding. Its not giving any error to. Its appear just blank page. I have checked my db connection and its working fine. I do not know what is issue in it. let me know if anyone can help me for solve it.
My full PHP file is like below
<?php
error_reporting(E_ALL);
include_once("includes/connection.php");
$input = "hello";
$sql = "SELECT answer FROM faq WHERE question = 'hello' ORDER BY id DESC LIMIT 1";
$result = mysqli_query($mysqli,$sql);
if ($result !== false) {
$value = mysqli_fetch_field($result);
echo $value;
} else {
echo "errors";
}
?>
My connection file is like below
<?php
error_reporting(0);
ob_start();
session_start();
header("Content-Type: text/html;charset=UTF-8");
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '');
DEFINE ('DB_HOST', 'localhost'); //host name depends on server
DEFINE ('DB_NAME', 'test');
$mysqli =mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mysqli_set_charset($mysqli,"utf8mb4");
mysqli_query($mysqli,"SET NAMES 'utf8mb4'");
?>
Thanks
php mysql mysqli
php mysql mysqli
edited Nov 21 '18 at 9:23
Julian Stark
1,2681426
1,2681426
asked Nov 21 '18 at 5:48
MiraMira
204
204
If connection is working then check query again, if this query really fetching any data for you.
– Prashant Deshmukh.....
Nov 21 '18 at 5:58
Try echo "Value => ".$value; instead of echo $value; It will be able to detect the blank value, if any.
– ChintanThummar
Nov 21 '18 at 5:59
@ChintanThummar its still blank page
– Mira
Nov 21 '18 at 6:05
@PrashantDeshmukh.....I have double checked and its working fine in phpmyadmin
– Mira
Nov 21 '18 at 6:06
check if the condition comes to if {} or else{} by puting exit; within if and else on the start like echo 'test'; exit; and echo 'test1' exit; Or you can add die() in query to check
– Chris shi
Nov 21 '18 at 6:48
add a comment |
If connection is working then check query again, if this query really fetching any data for you.
– Prashant Deshmukh.....
Nov 21 '18 at 5:58
Try echo "Value => ".$value; instead of echo $value; It will be able to detect the blank value, if any.
– ChintanThummar
Nov 21 '18 at 5:59
@ChintanThummar its still blank page
– Mira
Nov 21 '18 at 6:05
@PrashantDeshmukh.....I have double checked and its working fine in phpmyadmin
– Mira
Nov 21 '18 at 6:06
check if the condition comes to if {} or else{} by puting exit; within if and else on the start like echo 'test'; exit; and echo 'test1' exit; Or you can add die() in query to check
– Chris shi
Nov 21 '18 at 6:48
If connection is working then check query again, if this query really fetching any data for you.
– Prashant Deshmukh.....
Nov 21 '18 at 5:58
If connection is working then check query again, if this query really fetching any data for you.
– Prashant Deshmukh.....
Nov 21 '18 at 5:58
Try echo "Value => ".$value; instead of echo $value; It will be able to detect the blank value, if any.
– ChintanThummar
Nov 21 '18 at 5:59
Try echo "Value => ".$value; instead of echo $value; It will be able to detect the blank value, if any.
– ChintanThummar
Nov 21 '18 at 5:59
@ChintanThummar its still blank page
– Mira
Nov 21 '18 at 6:05
@ChintanThummar its still blank page
– Mira
Nov 21 '18 at 6:05
@PrashantDeshmukh.....I have double checked and its working fine in phpmyadmin
– Mira
Nov 21 '18 at 6:06
@PrashantDeshmukh.....I have double checked and its working fine in phpmyadmin
– Mira
Nov 21 '18 at 6:06
check if the condition comes to if {} or else{} by puting exit; within if and else on the start like echo 'test'; exit; and echo 'test1' exit; Or you can add die() in query to check
– Chris shi
Nov 21 '18 at 6:48
check if the condition comes to if {} or else{} by puting exit; within if and else on the start like echo 'test'; exit; and echo 'test1' exit; Or you can add die() in query to check
– Chris shi
Nov 21 '18 at 6:48
add a comment |
2 Answers
2
active
oldest
votes
According to the Manual mysqli_fetch_field()
will return an object. You can't echo()
an Object. But you can print the result like
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %sn", $finfo->name);
printf("Table: %sn", $finfo->table);
printf("max. Len: %dn", $finfo->max_length);
printf("Flags: %dn", $finfo->flags);
printf("Type: %dnn", $finfo->type);
}
pos worth noting you can echo object properties, e.g.echo $info->name
– treyBake
Nov 21 '18 at 9:35
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
add a comment |
enable error reporting in PHP as:
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
This will show the error list on page.
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53405937%2fmysqli-query-does-not-working-blank-php-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
According to the Manual mysqli_fetch_field()
will return an object. You can't echo()
an Object. But you can print the result like
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %sn", $finfo->name);
printf("Table: %sn", $finfo->table);
printf("max. Len: %dn", $finfo->max_length);
printf("Flags: %dn", $finfo->flags);
printf("Type: %dnn", $finfo->type);
}
pos worth noting you can echo object properties, e.g.echo $info->name
– treyBake
Nov 21 '18 at 9:35
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
add a comment |
According to the Manual mysqli_fetch_field()
will return an object. You can't echo()
an Object. But you can print the result like
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %sn", $finfo->name);
printf("Table: %sn", $finfo->table);
printf("max. Len: %dn", $finfo->max_length);
printf("Flags: %dn", $finfo->flags);
printf("Type: %dnn", $finfo->type);
}
pos worth noting you can echo object properties, e.g.echo $info->name
– treyBake
Nov 21 '18 at 9:35
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
add a comment |
According to the Manual mysqli_fetch_field()
will return an object. You can't echo()
an Object. But you can print the result like
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %sn", $finfo->name);
printf("Table: %sn", $finfo->table);
printf("max. Len: %dn", $finfo->max_length);
printf("Flags: %dn", $finfo->flags);
printf("Type: %dnn", $finfo->type);
}
According to the Manual mysqli_fetch_field()
will return an object. You can't echo()
an Object. But you can print the result like
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %sn", $finfo->name);
printf("Table: %sn", $finfo->table);
printf("max. Len: %dn", $finfo->max_length);
printf("Flags: %dn", $finfo->flags);
printf("Type: %dnn", $finfo->type);
}
answered Nov 21 '18 at 5:58
AbhishekAbhishek
9736
9736
pos worth noting you can echo object properties, e.g.echo $info->name
– treyBake
Nov 21 '18 at 9:35
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
add a comment |
pos worth noting you can echo object properties, e.g.echo $info->name
– treyBake
Nov 21 '18 at 9:35
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
pos worth noting you can echo object properties, e.g.
echo $info->name
– treyBake
Nov 21 '18 at 9:35
pos worth noting you can echo object properties, e.g.
echo $info->name
– treyBake
Nov 21 '18 at 9:35
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
@treyBake yes, I know. I just copied the code from an example from the manual. Thought it would be better than just echoing everything
– Abhishek
Nov 21 '18 at 9:55
add a comment |
enable error reporting in PHP as:
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
This will show the error list on page.
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
add a comment |
enable error reporting in PHP as:
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
This will show the error list on page.
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
add a comment |
enable error reporting in PHP as:
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
This will show the error list on page.
enable error reporting in PHP as:
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
This will show the error list on page.
edited Nov 21 '18 at 10:48
bobbyrne01
2,17564293
2,17564293
answered Nov 21 '18 at 6:41
anju dhimananju dhiman
11
11
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
add a comment |
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
although I agree with the ini_set idea - it's not directly an answer to the issue and better suited as a comment. I know you don't have enough rep to comment but it's best to wait til you can answer a question with 100% certainty to gain enough rep to start commenting.
– treyBake
Nov 21 '18 at 9:29
add a comment |
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.
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%2f53405937%2fmysqli-query-does-not-working-blank-php-page%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
If connection is working then check query again, if this query really fetching any data for you.
– Prashant Deshmukh.....
Nov 21 '18 at 5:58
Try echo "Value => ".$value; instead of echo $value; It will be able to detect the blank value, if any.
– ChintanThummar
Nov 21 '18 at 5:59
@ChintanThummar its still blank page
– Mira
Nov 21 '18 at 6:05
@PrashantDeshmukh.....I have double checked and its working fine in phpmyadmin
– Mira
Nov 21 '18 at 6:06
check if the condition comes to if {} or else{} by puting exit; within if and else on the start like echo 'test'; exit; and echo 'test1' exit; Or you can add die() in query to check
– Chris shi
Nov 21 '18 at 6:48