PHP code gets errors in server but works fine in local





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I have my site running well on my local but when I uploaded it, the php code gets some error,



Warning: mysqli::prepare(): Couldn't fetch mysqli in /home/gh/public_html/abida/C/login.php on line 15



Fatal error: Call to a member function bind_param() on null in /home/gh/public_html/abida/C/login.php on line 16



        <?php
require '../api/dbcon.php';
require '../api/apiOnly.php';
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
//FACULTY - USER LOGIN
if(isset($_POST['login'])){
//do query here
$stmt = $conn->prepare('SELECT username, campus, designation FROM accounts where username = ? AND password = ? ');
$stmt->bind_param('ss', $u, $p);
$u=$_POST['username'];
$p=md5($_POST['password']);
$stmt->execute();
$stmt->bind_result($username,$campus, $designation);
if($stmt->fetch()>0){
$_SESSION['usr_fullname'] = $username;
$_SESSION['usr_type'] = $designation;
$_SESSION['usr_campus'] = $campus;
if($_SESSION['usr_type']=='admin'){
header('location: home.php');
exit();
}else if($_SESSION['usr_type']=='director'){
header('location: director-index.php');
exit();
}
}else{
$faculty = json_decode($api->authenticate_student($_POST['username'],$_POST['password']),true);
if(!empty($faculty[0]['usr_fullname'])){
$_SESSION['usr_fullname'] = $faculty[0]['usr_fullname'];
$_SESSION['usr_type'] = 'faculty';
header('location: faculty-index.php');
}else{
echo "<script type='text/javascript'>
alert ('Username and Password unmatched!');
window.location.href='login.php';</script>";
}
}
$stmt->close();
$conn->close();
}
?>


dbcon.php



      <?php
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
error_reporting(E_ALL & E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '0');
ini_set('error_log', './');

$dbhost = 'localhost';
$dbuser = '------';
$dbpass = '------';
$dbtable = "-----";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>


Sorry I am new to this, should I change the localhost too? where can I find the right name to put there.










share|improve this question

























  • Use absolute pathes with include/require.. I'd assume your includes are not loaded, therefore the $conn is not initialized.

    – Lars Stegelitz
    Nov 25 '18 at 9:01











  • require '../api/dbcon.php'; check whether this file correctly included.

    – Nadee
    Nov 25 '18 at 9:07











  • @LarsStegelitz how can I check if it is loaded? I mean I checked the location of the file and I think it should be fine

    – Code-Me
    Nov 25 '18 at 9:17











  • @Nadee sorry I dont know how, can you teach me that?

    – Code-Me
    Nov 25 '18 at 9:18











  • var_dump( file_exists('../api/dbcon.php'), realpath('../api/dbcon.php') );

    – Lars Stegelitz
    Nov 25 '18 at 9:27


















-1















I have my site running well on my local but when I uploaded it, the php code gets some error,



Warning: mysqli::prepare(): Couldn't fetch mysqli in /home/gh/public_html/abida/C/login.php on line 15



Fatal error: Call to a member function bind_param() on null in /home/gh/public_html/abida/C/login.php on line 16



        <?php
require '../api/dbcon.php';
require '../api/apiOnly.php';
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
//FACULTY - USER LOGIN
if(isset($_POST['login'])){
//do query here
$stmt = $conn->prepare('SELECT username, campus, designation FROM accounts where username = ? AND password = ? ');
$stmt->bind_param('ss', $u, $p);
$u=$_POST['username'];
$p=md5($_POST['password']);
$stmt->execute();
$stmt->bind_result($username,$campus, $designation);
if($stmt->fetch()>0){
$_SESSION['usr_fullname'] = $username;
$_SESSION['usr_type'] = $designation;
$_SESSION['usr_campus'] = $campus;
if($_SESSION['usr_type']=='admin'){
header('location: home.php');
exit();
}else if($_SESSION['usr_type']=='director'){
header('location: director-index.php');
exit();
}
}else{
$faculty = json_decode($api->authenticate_student($_POST['username'],$_POST['password']),true);
if(!empty($faculty[0]['usr_fullname'])){
$_SESSION['usr_fullname'] = $faculty[0]['usr_fullname'];
$_SESSION['usr_type'] = 'faculty';
header('location: faculty-index.php');
}else{
echo "<script type='text/javascript'>
alert ('Username and Password unmatched!');
window.location.href='login.php';</script>";
}
}
$stmt->close();
$conn->close();
}
?>


dbcon.php



      <?php
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
error_reporting(E_ALL & E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '0');
ini_set('error_log', './');

$dbhost = 'localhost';
$dbuser = '------';
$dbpass = '------';
$dbtable = "-----";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>


Sorry I am new to this, should I change the localhost too? where can I find the right name to put there.










share|improve this question

























  • Use absolute pathes with include/require.. I'd assume your includes are not loaded, therefore the $conn is not initialized.

    – Lars Stegelitz
    Nov 25 '18 at 9:01











  • require '../api/dbcon.php'; check whether this file correctly included.

    – Nadee
    Nov 25 '18 at 9:07











  • @LarsStegelitz how can I check if it is loaded? I mean I checked the location of the file and I think it should be fine

    – Code-Me
    Nov 25 '18 at 9:17











  • @Nadee sorry I dont know how, can you teach me that?

    – Code-Me
    Nov 25 '18 at 9:18











  • var_dump( file_exists('../api/dbcon.php'), realpath('../api/dbcon.php') );

    – Lars Stegelitz
    Nov 25 '18 at 9:27














-1












-1








-1








I have my site running well on my local but when I uploaded it, the php code gets some error,



Warning: mysqli::prepare(): Couldn't fetch mysqli in /home/gh/public_html/abida/C/login.php on line 15



Fatal error: Call to a member function bind_param() on null in /home/gh/public_html/abida/C/login.php on line 16



        <?php
require '../api/dbcon.php';
require '../api/apiOnly.php';
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
//FACULTY - USER LOGIN
if(isset($_POST['login'])){
//do query here
$stmt = $conn->prepare('SELECT username, campus, designation FROM accounts where username = ? AND password = ? ');
$stmt->bind_param('ss', $u, $p);
$u=$_POST['username'];
$p=md5($_POST['password']);
$stmt->execute();
$stmt->bind_result($username,$campus, $designation);
if($stmt->fetch()>0){
$_SESSION['usr_fullname'] = $username;
$_SESSION['usr_type'] = $designation;
$_SESSION['usr_campus'] = $campus;
if($_SESSION['usr_type']=='admin'){
header('location: home.php');
exit();
}else if($_SESSION['usr_type']=='director'){
header('location: director-index.php');
exit();
}
}else{
$faculty = json_decode($api->authenticate_student($_POST['username'],$_POST['password']),true);
if(!empty($faculty[0]['usr_fullname'])){
$_SESSION['usr_fullname'] = $faculty[0]['usr_fullname'];
$_SESSION['usr_type'] = 'faculty';
header('location: faculty-index.php');
}else{
echo "<script type='text/javascript'>
alert ('Username and Password unmatched!');
window.location.href='login.php';</script>";
}
}
$stmt->close();
$conn->close();
}
?>


dbcon.php



      <?php
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
error_reporting(E_ALL & E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '0');
ini_set('error_log', './');

$dbhost = 'localhost';
$dbuser = '------';
$dbpass = '------';
$dbtable = "-----";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>


Sorry I am new to this, should I change the localhost too? where can I find the right name to put there.










share|improve this question
















I have my site running well on my local but when I uploaded it, the php code gets some error,



Warning: mysqli::prepare(): Couldn't fetch mysqli in /home/gh/public_html/abida/C/login.php on line 15



Fatal error: Call to a member function bind_param() on null in /home/gh/public_html/abida/C/login.php on line 16



        <?php
require '../api/dbcon.php';
require '../api/apiOnly.php';
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
//FACULTY - USER LOGIN
if(isset($_POST['login'])){
//do query here
$stmt = $conn->prepare('SELECT username, campus, designation FROM accounts where username = ? AND password = ? ');
$stmt->bind_param('ss', $u, $p);
$u=$_POST['username'];
$p=md5($_POST['password']);
$stmt->execute();
$stmt->bind_result($username,$campus, $designation);
if($stmt->fetch()>0){
$_SESSION['usr_fullname'] = $username;
$_SESSION['usr_type'] = $designation;
$_SESSION['usr_campus'] = $campus;
if($_SESSION['usr_type']=='admin'){
header('location: home.php');
exit();
}else if($_SESSION['usr_type']=='director'){
header('location: director-index.php');
exit();
}
}else{
$faculty = json_decode($api->authenticate_student($_POST['username'],$_POST['password']),true);
if(!empty($faculty[0]['usr_fullname'])){
$_SESSION['usr_fullname'] = $faculty[0]['usr_fullname'];
$_SESSION['usr_type'] = 'faculty';
header('location: faculty-index.php');
}else{
echo "<script type='text/javascript'>
alert ('Username and Password unmatched!');
window.location.href='login.php';</script>";
}
}
$stmt->close();
$conn->close();
}
?>


dbcon.php



      <?php
if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
session_start();
}
error_reporting(E_ALL & E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '0');
ini_set('error_log', './');

$dbhost = 'localhost';
$dbuser = '------';
$dbpass = '------';
$dbtable = "-----";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>


Sorry I am new to this, should I change the localhost too? where can I find the right name to put there.







php forms session mysqli server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 14:28









Funk Forty Niner

1




1










asked Nov 25 '18 at 8:56









Code-MeCode-Me

12




12













  • Use absolute pathes with include/require.. I'd assume your includes are not loaded, therefore the $conn is not initialized.

    – Lars Stegelitz
    Nov 25 '18 at 9:01











  • require '../api/dbcon.php'; check whether this file correctly included.

    – Nadee
    Nov 25 '18 at 9:07











  • @LarsStegelitz how can I check if it is loaded? I mean I checked the location of the file and I think it should be fine

    – Code-Me
    Nov 25 '18 at 9:17











  • @Nadee sorry I dont know how, can you teach me that?

    – Code-Me
    Nov 25 '18 at 9:18











  • var_dump( file_exists('../api/dbcon.php'), realpath('../api/dbcon.php') );

    – Lars Stegelitz
    Nov 25 '18 at 9:27



















  • Use absolute pathes with include/require.. I'd assume your includes are not loaded, therefore the $conn is not initialized.

    – Lars Stegelitz
    Nov 25 '18 at 9:01











  • require '../api/dbcon.php'; check whether this file correctly included.

    – Nadee
    Nov 25 '18 at 9:07











  • @LarsStegelitz how can I check if it is loaded? I mean I checked the location of the file and I think it should be fine

    – Code-Me
    Nov 25 '18 at 9:17











  • @Nadee sorry I dont know how, can you teach me that?

    – Code-Me
    Nov 25 '18 at 9:18











  • var_dump( file_exists('../api/dbcon.php'), realpath('../api/dbcon.php') );

    – Lars Stegelitz
    Nov 25 '18 at 9:27

















Use absolute pathes with include/require.. I'd assume your includes are not loaded, therefore the $conn is not initialized.

– Lars Stegelitz
Nov 25 '18 at 9:01





Use absolute pathes with include/require.. I'd assume your includes are not loaded, therefore the $conn is not initialized.

– Lars Stegelitz
Nov 25 '18 at 9:01













require '../api/dbcon.php'; check whether this file correctly included.

– Nadee
Nov 25 '18 at 9:07





require '../api/dbcon.php'; check whether this file correctly included.

– Nadee
Nov 25 '18 at 9:07













@LarsStegelitz how can I check if it is loaded? I mean I checked the location of the file and I think it should be fine

– Code-Me
Nov 25 '18 at 9:17





@LarsStegelitz how can I check if it is loaded? I mean I checked the location of the file and I think it should be fine

– Code-Me
Nov 25 '18 at 9:17













@Nadee sorry I dont know how, can you teach me that?

– Code-Me
Nov 25 '18 at 9:18





@Nadee sorry I dont know how, can you teach me that?

– Code-Me
Nov 25 '18 at 9:18













var_dump( file_exists('../api/dbcon.php'), realpath('../api/dbcon.php') );

– Lars Stegelitz
Nov 25 '18 at 9:27





var_dump( file_exists('../api/dbcon.php'), realpath('../api/dbcon.php') );

– Lars Stegelitz
Nov 25 '18 at 9:27












1 Answer
1






active

oldest

votes


















-1














Declare



$stmt->bind_param('ss', $u, $p);


After



  $u=$_POST['username'];
$p=md5($_POST['password']);





share|improve this answer
























  • doesnt work bro :'(

    – Code-Me
    Nov 25 '18 at 9:24











  • $stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

    – Mohsin Mujawar
    Nov 25 '18 at 9:37












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466006%2fphp-code-gets-errors-in-server-but-works-fine-in-local%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














Declare



$stmt->bind_param('ss', $u, $p);


After



  $u=$_POST['username'];
$p=md5($_POST['password']);





share|improve this answer
























  • doesnt work bro :'(

    – Code-Me
    Nov 25 '18 at 9:24











  • $stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

    – Mohsin Mujawar
    Nov 25 '18 at 9:37
















-1














Declare



$stmt->bind_param('ss', $u, $p);


After



  $u=$_POST['username'];
$p=md5($_POST['password']);





share|improve this answer
























  • doesnt work bro :'(

    – Code-Me
    Nov 25 '18 at 9:24











  • $stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

    – Mohsin Mujawar
    Nov 25 '18 at 9:37














-1












-1








-1







Declare



$stmt->bind_param('ss', $u, $p);


After



  $u=$_POST['username'];
$p=md5($_POST['password']);





share|improve this answer













Declare



$stmt->bind_param('ss', $u, $p);


After



  $u=$_POST['username'];
$p=md5($_POST['password']);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 9:07









Mohsin MujawarMohsin Mujawar

766




766













  • doesnt work bro :'(

    – Code-Me
    Nov 25 '18 at 9:24











  • $stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

    – Mohsin Mujawar
    Nov 25 '18 at 9:37



















  • doesnt work bro :'(

    – Code-Me
    Nov 25 '18 at 9:24











  • $stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

    – Mohsin Mujawar
    Nov 25 '18 at 9:37

















doesnt work bro :'(

– Code-Me
Nov 25 '18 at 9:24





doesnt work bro :'(

– Code-Me
Nov 25 '18 at 9:24













$stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

– Mohsin Mujawar
Nov 25 '18 at 9:37





$stmt->bind_result($username,$campus, $designation); after if($stmt->fetch()>0){

– Mohsin Mujawar
Nov 25 '18 at 9:37




















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466006%2fphp-code-gets-errors-in-server-but-works-fine-in-local%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()