Reputation: 41
Here is my PHP code:
$query = $sdb->prepare("SELECT * FROM `t_comments` WHERE `a_link` = ?");
$query->bindValue(1, $_GET["link"]);
$query->execute();
and here is my JSON request in Android:
JSONObject json = jParser.makeHttpRequest("http://serverip/json/getcomments.php?link=" + index, "GET", params);
Actually, this code works if I remove link request in Activity.
Also, if I replace $_GET
with ID
in PHP, but index
will change on each request so.
SOLVED:
i needed to use Params list to add GET parameter inside
simply with params.add(new BasicNameValuePair("STRING NAME", SOMETHING TO STORE));
Upvotes: 0
Views: 276
Reputation: 2781
<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
$sth->bindValue(':colour', $colour, PDO::PARAM_STR);
$sth->execute();
?>
In your code:
if(isset($_GET["link"])){
$aVarName = $_GET["link"];
$query->bindValue(1, $aVarName, PDO::PARAM_INT);
} else {
// Some error or default value.
}
Upvotes: 0
Reputation: 3965
$query = $sdb->prepare("SELECT * FROM `t_comments` WHERE `a_link` = :link");
$query->bindValue(':link', $_GET["link"]);
$query->execute();
Upvotes: 1