Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP using $_GET at sql query returning no results
    primarykey
    data
    text
    <p>I have this php file in which i send a variable called user_email in an url like this:</p> <p>http://<strong><em>*</em>**<em>*</em>**<em>*</em>***</strong>/android_connect/get_all_products.php?user_email="m" </p> <p>through my android app code.</p> <p>However even if it should return me some data it returns me "No products found" from the else! If i use the test1 query however it returns me the right data! I know that the code is valnurable to SQL Injection but what i have to do to fix it like this?? Please help i really need this!!!!!!!</p> <pre><code>&lt;?php /* * Following code will list all the products */ // array for JSON response $response = array(); $user_email = $_REQUEST['user_email']; //echo $user_email; // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $db = new DB_CONNECT(); // get all products from products table $test = "SELECT *FROM products WHERE user_email= '" . $user_email . "'"; //$test1= "SELECT * FROM products where user_email='m'" ; //echo $test; $result = mysql_query($test) or die(mysql_error()); // check for empty result if (mysql_num_rows($result) &gt; 0) { // looping through all results // products node $response["products"] = array(); while ($row = mysql_fetch_array($result)) { // temp user array $product = array(); $product["pid"] = $row["pid"]; $product["firstname"] = $row["firstname"]; $product["lastname"] = $row["lastname"]; $product["email"] = $row["email"]; $product["phone"] = $row["phone"]; $product["address"] = $row["address"]; $product["created_at"] = $row["created_at"]; $product["updated_at"] = $row["updated_at"]; $product["user_email"] = $row["user_email"]; // push single product into final response array array_push($response["products"], $product); } // success $response["success"] = 1; // echoing JSON response echo json_encode($response); } else { // no products found $response["success"] = 0; $response["message"] = "No products found"; // echo no users JSON echo json_encode($response); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload