A PHP file has been set up in order to contact a SQL database and retrieve the article with the corresponding ArticleID which I append to the end of the URL.
For example, www.example.com/retrieveArticle.php?ArticleID=1
Currently, the webpage does not show any text output whereas I expected to find one row output as a JSON format.
Note that my table is called Customer.
Code
<?php
if(issert($_REQUEST["ArticleID"]))
{
$con = mysql_connect("localhost","createyo_james","password");
if(!$con)
{
die("Could not connect: " .mysql_error());
}
mysql_select_db("createyo_TestDatabase", $con);
$articleID = $_REQUEST["ArticleID"];
$result = mysql_query("SELECT * FROM Customer WHERE ID = "$articleID" ") or die("Errant query:");
while($row = mysql_fetch_assoc($result))
{
$output[]=$row;
}
print(json_encode($output));
mysql_close($con);
}
else
{
$output = "not found";
print(json_encode($output));
}
?>
Edit:
Since many of the solutions have not worked it may be due to incorrect database information. I know the connection details are correct as I have similar PHP files connected to the same DB. However, I might be wrong about the table structure when getting ID etc...
Code Attempt 2
<?php
if(isset($_GET["ArticleID"]))
{
$con = mysql_connect("localhost","createyo_james","password");
if(!$con)
{
die("Could not connect: " .mysql_error());
}
mysql_select_db("createyo_TestDatabase", $con);
$articleID = mysql_real_escape_string($_GET["ArticleID"]);
$result = mysql_query("SELECT * FROM Customer WHERE ID = "$ArticleID"") or die("Errant query:");
while($row = mysql_fetch_assoc($result)) { array_push($output,$row); } echo json_endode($output);die;
mysql_close($con);
}
else
{
$output = "not found";
echo json_encode($output);
}
?>