PDA

View Full Version : SQL syntax correct?


gilgalbiblewhee
04-17-2008, 12:15 AM
Can anyone tell me where I went wrong in this?

INSERT INTO boti_pages (title) VALUES ('3') WHERE class LIKE '%APFont00003%' AND page_num = '264' AND title != '1' AND title != '2'

kbluhm
04-17-2008, 12:19 AM
What is the error you are receiving?

gilgalbiblewhee
04-17-2008, 12:21 AM
What is the error you are receiving?

If I knew the error I wouldn't be asking. One thing I know is that when I used ANDs too often something went wrong.

gilgalbiblewhee
04-17-2008, 12:42 AM
Ok I changed it to :
$sql3 = "INSERT INTO boti_pages (title) VALUES ('3') WHERE id = '".$row2['id']."' AND (title !='1' OR title != '2')";

But the same...no results.

kbluhm
04-17-2008, 12:47 AM
If I knew the error I wouldn't be asking. One thing I know is that when I used ANDs too often something went wrong.

How do you expect us to fix the error when you don't even know what the error is?

Have a look at mysql_error(), then get back to us. ;)

gilgalbiblewhee
04-17-2008, 01:42 AM
How do you expect us to fix the error when you don't even know what the error is?

Have a look at mysql_error(), then get back to us. ;)

Howcome you don't know the answer before the question?

Kidding.

Isn't this the error script?
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

CFMaBiSmAd
04-17-2008, 02:00 AM
That code is only checking if the mysql_connect() works, not if the mysql_query() worked.

Your query is an INSERT, but it has a WHERE clause. A WHERE clause in an INSERT has no meaning.

o0O0o.o0O0o
04-17-2008, 02:26 AM
I think he wants to use Update statement

gilgalbiblewhee
04-17-2008, 02:28 AM
That code is only checking if the mysql_connect() works, not if the mysql_query() worked.

Your query is an INSERT, but it has a WHERE clause. A WHERE clause in an INSERT has no meaning.

Ok I changed it to UPDATE:

UPDATE boti_pages SET title = '3' WHERE id = '13113' AND (title !='1' OR title != '2')
But I see no change.

kbluhm
04-17-2008, 03:06 AM
Ok, one more time... what is the error?

Here is what you do:

$sql = "UPDATE boti_pages SET title = '3' WHERE id = '13113' AND (title !='1' OR title != '2')";
$res = mysql_query( $sql ) OR exit( 'Error: ' . mysql_error() );

...then, tell us exactly what the error is. :)

gilgalbiblewhee
04-17-2008, 04:47 AM
Ok, one more time... what is the error?

Here is what you do:

$sql = "UPDATE boti_pages SET title = '3' WHERE id = '13113' AND (title !='1' OR title != '2')";
$res = mysql_query( $sql ) OR exit( 'Error: ' . mysql_error() );

...then, tell us exactly what the error is. :)

Ok so I pasted the code above but before doing that I had a fresh look after going away from the computer and noticed that I had forgotten the following:
$sql3 = "UPDATE boti_pages SET title = '3' WHERE id = '".$row2['id']."' AND (title !='1' OR title != '2')";
$result3 = mysql_query($sql3) OR exit( 'Error: ' . mysql_error() );

Which was why it wasn't working.

aedrin
04-17-2008, 03:42 PM
Ok, one more time... what is the error?

...

...then, tell us exactly what the error is. :)

But the same...no results.

I think the problem has already been stated (4th message of the topic)

kbluhm
04-17-2008, 03:57 PM
I think the problem has already been stated (4th message of the topic)

You think so? I saw that... I was seeing if he was able to figure out that no results doesn't necessarily mean a bad query. :rolleyes:

gilgalbiblewhee
04-17-2008, 05:58 PM
You think so? I saw that... I was seeing if he was able to figure out that no results doesn't necessarily mean a bad query. :rolleyes:

No there was no error. But what I don't understand is how to make the statement work properly. What I mean is:
$sql3 = "UPDATE boti_pages SET title = '3' WHERE id = '".$row2['id']."' AND (title !='1' OR title != '2')";

I already have title = '1' and title = '2'. Now this is the 3rd query or $sql3. What I need is to pick up the $row2['id'] selected minus those that have been marked as id = 1 and id = 2.

It's not working because when it's replacing the title it's including those as well.