0

In my website, I use prepared statement in the login page. It was working fine till last day but now when login using username and password it says "unable to handle the request internal error 500". but its working fine in localhost also. Why this happened. All websites I used prepared statement that hosted in the server have the same problem. And when I remove the prapared statement from code its working fine.

if(isset($_POST['login']))
{
    $userid=$_POST['userid'];
    $password=$_POST['password'];
    $qry="select userid,password from login where userid=? and password=?";
    $ex=mysqli_prepare($con,$qry);
    mysqli_stmt_bind_param($ex,'ss',$userid,$password);
    mysqli_stmt_execute($ex);
    $res=mysqli_stmt_get_result($ex);
    if(mysqli_num_rows($res)>0)
    {
        header('location:home.php');
        $_SESSION['user']=$userid;
    }
}

when I remove the prepared statement and edit the code like this its working fine in server

if(isset($_POST['login']))
{
    $userid=$_POST['userid'];
    $password=$_POST['password'];
    $qry="select userid,password from login where userid='$userid' and password='$password'";
    $ex=mysqli_query($con,$qry);
    if(mysqli_num_rows($ex)>0)
    {
        header('location:home.php');
        $_SESSION['user']=$userid;
    }
}

I got the error message "PHP Fatal error: Call to undefined function mysqli_stmt_get_result()". But my doubt is this code was working fine a few days before. Then how it would get the error now.Please help me to find a solution. My problem is it was well working a few days ago. But now its not working . So the problem is not about code. May be its about hosting. But I have only less knowledge about hosting. So please any one can help me

user9255196
  • 3
  • 1
  • 7
  • You need to find the actual error message. Start by checking your servers error log. You can also change how PHP displays errors and tell it to show all errors directly on the screen (this is not something you want in production though, since it can show sensitive data, but during development, you should). Here's how to show all errors and warnings: https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings – M. Eriksson Jun 26 '18 at 05:18
  • - please go though the below link, you will find out the reason for the sudden break down in your website. http://www.nusphere.com/kb/phpmanual/function.mysqli-prepare.htm – Bhavya Hegde Jun 26 '18 at 05:19
  • **Never store passwords in clear text!**. Only store password hashes! Use PHP's [`password_hash()`](http://php.net/manual/en/function.password-hash.php) to create the hash and[`password_verify()`](http://php.net/manual/en/function.password-verify.php) to verify a generated hash. – M. Eriksson Jun 26 '18 at 05:19
  • 1
    @BhavyaHegde - If you know what's wrong with the OP's code, why not just point it out? – M. Eriksson Jun 26 '18 at 05:22
  • Please replace the $res=mysqli_stmt_get_result($ex); with $res=mysqli_stmt_bind_result($ex); – Bhavya Hegde Jun 26 '18 at 05:37
  • @BhavyaHegde - 1. Just changing that won't work since you actually need to bind the result to some variable (which your example is missing). 2. The OP isn't trying to get the actual result from the database but rather just wants to check if the query returned any result set at all. – M. Eriksson Jun 26 '18 at 05:43
  • Last time I was able to solve the same issue with my project only by replacing this. Sorry, it didn't help you. – Bhavya Hegde Jun 26 '18 at 05:46
  • Another thing you should add is proper error logging. You should read http://php.net/manual/en/mysqli.error.php and update your code to log any potential errors. That will help you find out why your prepares fail, if they do. – M. Eriksson Jun 26 '18 at 05:52
  • I got the error message "PHP Fatal error: Call to undefined function mysqli_stmt_get_result()". But my doubt is this code was working fine a few days before. Then how it would get the error now – user9255196 Jun 27 '18 at 06:10
  • 1
    Has your host changed/updated/moved their PHP installation…? – deceze Jul 09 '18 at 08:06
  • @deceze how could I know that. Actually I don't well known about server and hosting. I hosted my site in godaddy – user9255196 Jul 09 '18 at 09:26
  • Then contact GoDaddy support. – deceze Jul 09 '18 at 09:26
  • I contacted with them. But they said "its upto developer side and the problem is mysql error. Else anyone edited anything" – user9255196 Jul 09 '18 at 09:32
  • After following all of Magnus' advice... if you only want to know the rowcount and don't need any actual column data, write your SELECT clause to use `COUNT(*)` , then just refer to that value. The querying principle: Don't query for more than you need. – mickmackusa Jul 11 '18 at 09:25
  • @mickmackusa - Sorry..I didn't get you – user9255196 Jul 11 '18 at 10:51
  • Your login script is horribly and deeply flawed and should not used even if you get it to work. You have a lot of research and development to do. Too much to comment. – mickmackusa Jul 11 '18 at 10:54

0 Answers0