0

I have 3 columns in my table username, password and element. The value of element is 1. So I created a webpage If user insert the correct username and password I want my PHP to check that If element = 1 then do something I want and change element to 0. But If it is 0 so PHP do nothing. My problem is it's display white screen.

<?php
  require_once("function/func_connect.php");
  require_once("function/func_check.php");
  require_once("function/websend.php");
$objLogin = checkPassword($_POST['user_name'],$_POST['user_password'],$Cfg["table"]["user"]);
if($objLogin == false)
{
        include("state/login_failed.html");
        exit();
}
if($objLogin == true)
{
// I think the problem cause here How do I fix?
    mysql_query("SELECT element FROM authme WHERE username = $_POST['user_name']");
    echo "success";
}
    mysql_close();
?>

Thank you and sorry for my bad english.

  • Please stop using the `mysql_*` functions. They are considered to be deprecated and unsecure. You should look into using [`PDO`](http://php.net/manual/en/book.pdo.php) – Justin Wood Jan 22 '15 at 16:47
  • You should also turn on `Display Errors` in PHP while developing and there wouldn't have been a need for the question. It would have showed you the syntax error. – Panama Jack Jan 22 '15 at 16:48

1 Answers1

2

Your basic error is you are not wrapping your string value in quotes.

mysql_query("SELECT element FROM authme WHERE username = $_POST['user_name']");

should be

mysql_query("SELECT element FROM authme WHERE username = '$_POST['user_name']'");

But, just as important, you are wide open to SQL injections. You need to fix that ASAP.

You also need to turn on error reporting so you can see your errors instead of getting just a white screen.

FYI, you shouldn't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Conde
  • 217,595
  • 99
  • 455
  • 496