-3

I see that there's an issue with PHP showing the following error:

Warning: A non-numeric value encountered in on line

This is my code, I just want to pull an entry from the database with a unique ID number.

include("database_connection_information.php");     
$article_id = 2;
$sql = "SELECT article_title, article_text 
        FROM Articles 
        WHERE article_id = " + intval($article_id);
$result = $conn->query($sql);

This code as it is generates the error.

(Warning: A non-numeric value encountered describes the issue, but doesn't say how to work around it)

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 2
    replace the plus sign with a period. This isn't JS/C, it's PHP. Unless you're wanting to do math here on a column that is anything other than an integer. – Funk Forty Niner Mar 22 '18 at 22:31
  • 1
    For starter, since this isn't javascript, concatenation is done with a dot `.` not with a plus `+`. – N.B. Mar 22 '18 at 22:31
  • 1
    You should also read up on [**prepared statements**](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) so that you can prevent [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection). – Obsidian Age Mar 22 '18 at 22:32
  • @ObsidianAge He's using intval(), so there's no need for a prepared statement. – Funk Forty Niner Mar 22 '18 at 22:34
  • Good to know; didn't realise `invat()` negated the need for parameterisation :) – Obsidian Age Mar 22 '18 at 22:37
  • @ObsidianAge too bad there's no "syntax" highlight for sarcasm :) – N.B. Mar 23 '18 at 10:37

1 Answers1

1

it is necessary to merge with a dot, not with a plus.

include("database_connection_information.php"); 

$article_id = 2;
$sql = "SELECT article_title, article_text 
        FROM Articles 
        WHERE article_id = ".$article_id;
$result = $conn->query($sql);
Emin Uzun
  • 99
  • 6
  • Thanks for that. I had already tried using a dot instead of a plus, but with a dot the code stops working at that point, and doesn't process anything after that point. – Stephen Roberts Mar 23 '18 at 20:30