0

i am trying to select data from to table bast on column on thes tow table but i get duplicating data

table 1: ID P_name Image_url cat_number Price Foe T_email loc_a loc_o

table 2 : n_p Name Email Password Phone Location_lat Location_long
i jut wont only the wont to select when T_email= trader.Email

and it get all trader.Email in table 2

<?php


$host='127.0.0.1';


$username='root';
$pwd='123';


$db="catcher_database";



$con=mysqli_connect($host,$username,$pwd,$db) or die('Unable to connect');


$email = $_POST['email'];
$interrest_a=$_POST["interrest_a"];
$interrest_b=$_POST["interrest_b"];
$interrest_c=$_POST["interrest_c"];
$interrest_d=$_POST["interrest_d"];
//$interrest_e=$_POST["interrest_e"];
$interrest_e="Restaurants";
if(!empty($email)){

if(mysqli_connect_error($con))
{
    echo "Failed to Connect to Database ".mysqli_connect_error();
}




$sql="SELECT * FROM product,trader WHERE trader.Email=product.T_email and product.T_email = '$email'";




$result=mysqli_query($con,$sql);


if($result)
{
    while($row=mysqli_fetch_array($result))
    {
        $data[]=$row;
    }




    print(json_encode($data)); }
}
else
{

if(mysqli_connect_error($con))
{
    echo "Failed to Connect to Database ".mysqli_connect_error();
}




$sql="SELECT * FROM product,trader WHERE product.T_email = trader.Email  and product.cat_number='$interrest_a'or product.cat_number='$interrest_b'or product.cat_number='$interrest_c'or product.cat_number='$interrest_d'or product.cat_number='$interrest_e'";




$result=mysqli_query($con,$sql);


if($result)
{
    while($row=mysqli_fetch_array($result))
    {
        $data[]=$row;
    }




    print(json_encode($data)); }
}





mysqli_close($con);


?>
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
farazdaq
  • 9
  • 3
  • SELECT * FROM product,trader WHERE product.T_email=trader.Email – farazdaq Apr 25 '18 at 20:03
  • this my sql query – farazdaq Apr 25 '18 at 20:04
  • @Alex there was actually PHP there, it was just invisible – Don't Panic Apr 25 '18 at 20:08
  • @Don'tPanic Odd, ok, my bad. – Alex Howansky Apr 25 '18 at 20:10
  • Heh ok in that case... your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use prepared statements with bound parameters, via either [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php). [**This post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) has some good examples. – Alex Howansky Apr 25 '18 at 20:11
  • ok i will fex it but help me in the query – farazdaq Apr 25 '18 at 20:17

0 Answers0