Problem wih mysql_query()

hello again :smiley:

this is my new problem: I am trying to write a script in order to compare data between two tables of a db.

[php]
$sql = “SELECT * FROM table1
WHERE table1.id NOT IN
(SELECT table2.id FROM table2 WHERE table1.id=table2.id)”;

$res = mysql_query($sql)or die(“there is no hope any more!!”);

[/php]

The query is ok BUT it dosn’t work…i get the message “there is no hope”!!! :stuck_out_tongue:

any ideas?:slight_smile:

try
[php]
$sql = “SELECT * FROM table1
WHERE table1.id NOT IN
(SELECT table2.id FROM table2 WHERE table1.id=table2.id)”;

$res = mysql_query($sql)or die(“there is still hope:
”.myscql_error());
[/php]

and fix the query

hi and thanx for the reply :smiley:

i still get the same message,nothing changed :frowning:

did you replace with my codes?

you SHOULD not get the same message it should be different because i changed.

you getting this message “there is no hope any more!!”

with my code you get "there is still hope: "
and on a new line a more descriptive error.

can you post what you getting on the screen.

hi :smiley:

i get the message : “there is still some hope : No database selected”

this is the code:

[php]

<?php $mysqli=mysql_connect("localhost","username","password","data base"); if (mysqli_connect_errno()){ printf("connection failed"); } else { $sql = "SELECT * FROM table1 WHERE table1.id NOT IN (SELECT table2.id FROM table2 WHERE table1.id=table2.id)"; $res = mysql_query($sql)or die("there is still hope:
".myscql_error()); } ?>

[/php]

what am i doing wrong?

you not selecting the database.

so before $sql query insert this:

[php]
mysql_select_db(“Database_name”) or die(mysql_error());
[/php]

Great :slight_smile: now it works fine…

but why should i select the database? since i have a already set the connection shouldn’t it work properly without this line?

Sponsor our Newsletter | Privacy Policy | Terms of Service