-2

I'm trying to compare data from my table and another table together at the same time.

<?php

$check="select * from A where si='".$user."' and code = (select synpr from user)";

?>
Script47
  • 14,230
  • 4
  • 45
  • 66
  • 5
    Means the subquery returns more than 1 row, so you need a `WHERE` condition, or `LIMIT` inside the subquery. Maybe both. – Qirel Sep 18 '17 at 12:39
  • 2
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***. Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Sep 18 '17 at 12:39
  • 2
    a subquery cannot return more than one row when used with `=` . It's supposed to check a single value against another single value. It can't compare a single value to multiple possible values. Depending on your actual intention, either restrict the subquery so that it will return a single row containing the code, or change = to IN (so that you check whether `code` is found in at least one of the rows returned by the subquery) – ADyson Sep 18 '17 at 12:45

1 Answers1

2

You are missing a where condition in Code.

But what are you trying to compare? like does the user in synpr has to be the same user as si?

if so

SELECT * from A where si='$user' AND code = (SELECT synpr FROM user WHERE user='$user');

But since you are selecting synpr in Code, then i have no clue what you are trying to compare exactly. Anything else u can tell us with what you are trying to achieve?