-2
if ($con->connect_error) 
{
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM Accounts WHERE acccount_num ='$accountNum'";

$result = $con->query($sql);
//$row = $result->fetch_row();

$row = mysqli_fetch_assoc($result);
print (json_encode($row));

$con->close();

This is my php code for connecting to the database where it is failing. I checked the field names in the actual database and I also checked all my code in the java project where my code is actually using the database. Really new to the whole concept of databases and PHP.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
gurnii
  • 39
  • 1
  • 7
  • 2
    Add `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any `mysqli_` errors to generate an Exception that you can see on the browser and other errors will also be visible on your browser. – RiggsFolly Jun 01 '17 at 19:34
  • What is `$accountNum` set to? – RiggsFolly Jun 01 '17 at 19:35
  • Are you using the `mysqli_` or `PDO` database extension – RiggsFolly Jun 01 '17 at 19:36
  • 3
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Jun 01 '17 at 19:36

2 Answers2

-1

Use this

$sql = "SELECT * FROM Accounts WHERE acccount_num =$accountNum";

instead of

$sql = "SELECT * FROM Accounts WHERE acccount_num ='$accountNum'";
Wafula Samuel
  • 530
  • 1
  • 8
  • 25
-1

Try this or maybe you have an extra c in acccount_num.

 $sql = "SELECT * FROM `accounts` WHERE `acccount_num` ='".$accountNum."'"
Joe
  • 32
  • 9