-1

I have a mysqli_query like this:

SELECT a.* FROM (SELECT `id` as `id`, `age` as `age` FROM `register` WHERE `age` !="") as a INNER JOIN (SELECT `one` as `f1` FROM `friends` WHERE `two`='".$my_id."' UNION SELECT `two` as `f2` FROM `friends` WHERE `one` = '".$my_id."') as b ON a.id=b.f1

When I run this in my SQL it gives no error and shows a successful query but if I run it in my browser I get this error

( ! ) Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\functions.php on line 585

Please anyone with an idea on how I can fix this?

This is my entire code

<?php
    $con = mysqli_connect('localhost','root','');

    mysqli_select_db($con, 'qings');

    $my_id = '1';
    // the line below is my line 585
    $query = mysqli_query($con, "SELECT a.* FROM (SELECT `id` as `id`, `age` as `age` FROM `register` WHERE `age` !="") as a INNER JOIN (SELECT `one` as `f1` FROM `friends` WHERE `two`='".$my_id."' UNION SELECT `two` as `f2` FROM `friends` WHERE `one` = '".$my_id."') as b ON a.id=b.f1");

?>
KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31

2 Answers2

1

Change WHERE 'age' !="" to WHERE 'age' !=''

Use

$query = mysqli_query($con, "SELECT a.* FROM (SELECT `id` as `id`, `age` as `age` FROM `register` WHERE `age` !='') as a INNER JOIN (SELECT `one` as `f1` FROM `friends` WHERE `two`='".$my_id."' UNION SELECT `two` as `f2` FROM `friends` WHERE `one` = '".$my_id."') as b ON a.id=b.f1");
Fabio Widmer
  • 529
  • 1
  • 7
  • 19
0

You should just escape double quotes here

WHERE `age` != \"\"
revo
  • 47,783
  • 14
  • 74
  • 117
Nick
  • 41
  • 4