simple mysql question..plz answer :)

Reply

Join Date: Jan 2009
Posts: 103
Reputation: jakx12 is an unknown quantity at this point 
Solved Threads: 4
jakx12's Avatar
jakx12 jakx12 is offline Offline
Junior Poster

simple mysql question..plz answer :)

 
0
  #1
Feb 28th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 78
Reputation: rickya100 is an unknown quantity at this point 
Solved Threads: 1
rickya100 rickya100 is offline Offline
Junior Poster in Training

Re: simple mysql question..plz answer :)

 
0
  #2
Feb 28th, 2009
Hi,

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

Test it out.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 103
Reputation: jakx12 is an unknown quantity at this point 
Solved Threads: 4
jakx12's Avatar
jakx12 jakx12 is offline Offline
Junior Poster

Re: simple mysql question..plz answer :)

 
0
  #3
Feb 28th, 2009
tested it out but, it does not delete anything from the database but there is no error . So whats wrong?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 198
Reputation: MaxMumford is an unknown quantity at this point 
Solved Threads: 1
MaxMumford's Avatar
MaxMumford MaxMumford is offline Offline
Junior Poster

Re: simple mysql question..plz answer :)

 
0
  #4
Feb 28th, 2009
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...
Last edited by peter_budo; Mar 1st, 2009 at 6:27 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Ill solve somebody's thread someday! xD
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,429
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 132
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: simple mysql question..plz answer :)

 
0
  #5
Mar 2nd, 2009
Originally Posted by MaxMumford View Post
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:
  1. mysql_query("DELETE FROM `user_notifications` WHERE `username`='".mysql_real_escape_string($acc)."' AND `notification`='".mysql_real_escape_string($note2)."' ") or die(mysql_error());
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 28
Reputation: vinothkumarc is an unknown quantity at this point 
Solved Threads: 3
vinothkumarc vinothkumarc is offline Offline
Light Poster

Re: simple mysql question..plz answer :)

 
0
  #6
Mar 2nd, 2009
To be a better php programmer always use single quotes like this,
  1. mysql_query('DELETE FROM user_notifications WHERE username="'.mysql_real_escape_string($acc).'" AND notification="'.mysql_real_escape_string($note2).'"')
  2. 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)
Last edited by peter_budo; Mar 8th, 2009 at 6:41 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Thanks & Regards,
VinothKumar C
post2vinoth@gmail.com
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,429
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 132
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: simple mysql question..plz answer :)

 
0
  #7
Mar 2nd, 2009
Originally Posted by vinothkumarc View Post
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!!!
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 28
Reputation: vinothkumarc is an unknown quantity at this point 
Solved Threads: 3
vinothkumarc vinothkumarc is offline Offline
Light Poster

Re: simple mysql question..plz answer :)

 
0
  #8
Mar 2nd, 2009
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)
Thanks & Regards,
VinothKumar C
post2vinoth@gmail.com
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,429
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 132
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: simple mysql question..plz answer :)

 
0
  #9
Mar 3rd, 2009
Originally Posted by vinothkumarc View Post
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:
  1. $var="line1\nline2";
  2. mysql_query('INSERT INTO `table` SET `column`="'.$var.'"');
Would that record the following:
  1. line1
  2. 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.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 28
Reputation: vinothkumarc is an unknown quantity at this point 
Solved Threads: 3
vinothkumarc vinothkumarc is offline Offline
Light Poster

Re: simple mysql question..plz answer :)

 
0
  #10
Mar 3rd, 2009
ya ofcourse...
before executing the query.... the parser will parse the arguement... after that only the mysql_query function will execute the query...
Thanks & Regards,
VinothKumar C
post2vinoth@gmail.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC