0

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));

1

2 Answers 2

1
$query = $sdb->prepare("SELECT * FROM `t_comments` WHERE `a_link` = :link");
$query->bindValue(':link', $_GET["link"]);
$query->execute();
Sign up to request clarification or add additional context in comments.

1 Comment

it still does not works, plus this method used above proved that works (iv used in different conditions) but in this case idk, its just cant get $_GET value or idk whats happening $query->bindValue(1, 15); <- this code will work but...
0

From the documentation:

<?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.
}

3 Comments

Problem is solved, anyway thanks for finding time to help me :)
If the question is answered, chlick the green symbol below the left of the question. This marks the question as answered, and make it so other people can read an answer that helped solve the issue
well problem wasn`t in PHP, my PHP code worked very well it was inside json parse so... and by the way i already edited and added SOLVED + SOLUTION in main question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.