HollanderNL HollanderNL - 1 year ago 59
PHP Question

Select info from mysql-database and show on page

I am trying to show some info from a mysql database on a page, but I get an error. Used code:

if (isset($_GET["id"]));
$newsarticle = ($_GET["id"]);
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'XXXX';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$searchroute ="SELECT NewsText FROM News WHERE id=$newsarticle";
$handle = mysql_query($searchroute);
$NewsText = mysql_fetch_row($handle);

And later in my code:

<?php echo "$NewsText" ?>

What am I doing wrong?

Answer Source

mysql_fetch_row() will return array so in your case it should be, echo $NewsText[0];

If you use mysql_fetch_array() then you can use echo $NewsText['NewsText'];