-1

I am currenty trying to make a script using mysqli, However when i run it, it returns a 500 Internal error, But when i remove the fatch_array, it runs without it. I have been using PHP.Net mysqli_ Manual. PHP Code

<?php
{ /* Global Data */
$GetPath = $_GET['p'];
$SqlUser = "root";
$SqlPass = "***********";
$SqlHost = "localhost";
$SqlData = "Site";
}
{ /* Mysql Connect */
$Sql = new mysqli($SqlHost, $SqlUser, $SqlPass, $SqlData);
if ($Sql->connect_error) { die("Sorry, Could not connect (".$Sql->connect_errno.") ".$Sql->connect_error);}
}
{ /* Test */
$Page = $Sql->real_escape_string($GetPath);
$SqlData = "SELECT * FROM pages WHERE Page = '".$Page."'";
$SqlQuery = $Sql->query($SqlData);
$Data = $SqlQuery->fetch_array(MYSQLI_ASSOC);
echo $Data['Title'];
$Sql->close();
}
?>

So what causes this? I used fefore the mysql_/ commands and now I'm switching to mysqli_*

Teknikk
  • 251
  • 1
  • 8
  • 22
  • 1
    Are you sure that it's `fetch_array()` causing the 500 error? Do you have an error message? – Tchoupi Aug 29 '12 at 17:44
  • @MathieuImbert When I remove the line containing the fetch_array() it runs without a error, and it only says HTTP-feil 500 (Internal Server Error) In google chrome when i run it. – Teknikk Aug 29 '12 at 17:47
  • You need to enable error reporting, `ini_set('display_errors', 1); ini_set('error_reporting', -1);` – Tchoupi Aug 29 '12 at 17:52
  • 1
    @MathieuImbert Enabled it and it returned this "Notice: Undefined index: p in X:\WebSite\wwwrootTF2Gametek\php.php on line 4 Fatal error: Call to a member function fetch_array() on a non-object in X:\WebSite\wwwrootTF2Gametek\php.php on line 18" – Teknikk Aug 29 '12 at 17:53

2 Answers2

0

Your code is fine. Your query is getting wrong.

One thing is which is causing it is $GetPath = $_GET['p'];

Either it's empty or having a value which making it wrong query.

Or you are having a wrong table name.

Abhishek
  • 838
  • 1
  • 6
  • 9
-1

You should not assume that your query succeed:

$SqlQuery = $Sql->query($SqlData);

if (!$SqlQuery) {
    echo $mysqli->error;
}

In your case $_GET['p'] is undefined, it's probably what's causing your query to fail, but you'll never know unless you check for errors.

Tchoupi
  • 14,560
  • 5
  • 37
  • 71