Ok so what i'd like to know is how to have two where statements in a mysql delete query. I get an error if i do this:

mysql_query("DELETE FROM user_notifications WHERE username='$acc' AND WHERE notification='$note2'")  
or die(mysql_error());

Any help would be much appreciated, I know this is a silly question, but i havnt done any php programming for a couple of months and need to get back into it!

Thanks,

jakx12

Hi,

Don't think you need the second WHERE, just the AND.

Test it out.

tested it out but, it does not delete anything from the database :( but there is no error :). So whats wrong?

mysql_query("DELETE FROM user_notifications WHERE username='".$acc."' AND notification='".$note2."' "); that should be fine. if its not, try checking your $acc and $note2 variables...

mysql_query("DELETE FROM user_notifications WHERE username='".$acc."' AND notification='".$note2."' "); that should be fine. if its not, try checking your $acc and $note2 variables...

You also need to escape the variables like this:

mysql_query("DELETE FROM `user_notifications` WHERE `username`='".mysql_real_escape_string($acc)."' AND `notification`='".mysql_real_escape_string($note2)."' ") or die(mysql_error());

To be a better php programmer always use single quotes like this,

mysql_query('DELETE FROM user_notifications WHERE username="'.mysql_real_escape_string($acc).'" AND notification="'.mysql_real_escape_string($note2).'"') 
or die(mysql_error());

bcoz: php parser will search and parse full string while using double quotes. :) - might look simple - but usefull tip(i think so)

To be a better php programmer always use single quotes like this,
mysql_query('DELETE FROM user_notifications WHERE username="'.mysql_real_escape_string($acc).'" AND notification="'.mysql_real_escape_string($note2).'"')
or die(mysql_error());
bcoz: php parser will search and parse full string while using double quotes. :) - might look simple - but usefull tip(i think so)

From what I have read in the past that is only a c++ thing. In c++ single quotes represent a single character where as with php, single quotes simply just doesn't apply new lines or returns (eg \n\r). Instead it will just display them as their literal characters. Where as double quotes in php allow those returns to be displayed instead of their literal characters. So you may find with your method that your returns will not turn out!!!

while using double quotes.. parser will search for php variable("my name is vinoth" instead use 'my name is vinoth') inside that string...(execution/parsing time will be greater). If we want to display the string with out any php variable('my name is '.$name)... then better to use single quotes...
its truth.... in PHP (I may not know about other languages)

while using double quotes.. parser will search for php variable("my name is vinoth" instead use 'my name is vinoth') inside that string...(execution/parsing time will be greater). If we want to display the string with out any php variable('my name is '.$name)... then better to use single quotes...
its truth.... in PHP (I may not know about other languages)

I can understand that when assigning a value to a variable/array that would be true but would it be the same with a mysql query. An example is the following:

$var="line1\nline2";
mysql_query('INSERT INTO `table` SET `column`="'.$var.'"');

Would that record the following:

line1
line2

Sort of a tricky thing when mixing two syntaxs together because you are unsure which syntax will be the one that will take place.

ya ofcourse...
before executing the query.... the parser will parse the arguement... after that only the mysql_query function will execute the query...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.