943,731 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 881
  • PHP RSS
Feb 28th, 2009
0

simple mysql question..plz answer :)

Expand Post »
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
Reputation Points: 10
Solved Threads: 5
Junior Poster
jakx12 is offline Offline
123 posts
since Jan 2009
Feb 28th, 2009
0

Re: simple mysql question..plz answer :)

Hi,

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

Test it out.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
rickya100 is offline Offline
78 posts
since Mar 2008
Feb 28th, 2009
0

Re: simple mysql question..plz answer :)

tested it out but, it does not delete anything from the database but there is no error . So whats wrong?
Reputation Points: 10
Solved Threads: 5
Junior Poster
jakx12 is offline Offline
123 posts
since Jan 2009
Feb 28th, 2009
0

Re: simple mysql question..plz answer :)

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.
Reputation Points: 32
Solved Threads: 3
Posting Whiz in Training
MaxMumford is offline Offline
228 posts
since Oct 2006
Mar 2nd, 2009
0

Re: simple mysql question..plz answer :)

Click to Expand / Collapse  Quote originally posted by MaxMumford ...
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:
php Syntax (Toggle Plain Text)
  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());
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Mar 2nd, 2009
0

Re: simple mysql question..plz answer :)

To be a better php programmer always use single quotes like this,
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 19
Solved Threads: 3
Light Poster
vinothkumarc is offline Offline
28 posts
since Apr 2008
Mar 2nd, 2009
0

Re: simple mysql question..plz answer :)

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!!!
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Mar 2nd, 2009
0

Re: simple mysql question..plz answer :)

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)
Reputation Points: 19
Solved Threads: 3
Light Poster
vinothkumarc is offline Offline
28 posts
since Apr 2008
Mar 3rd, 2009
0

Re: simple mysql question..plz answer :)

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:
php Syntax (Toggle Plain Text)
  1. $var="line1\nline2";
  2. mysql_query('INSERT INTO `table` SET `column`="'.$var.'"');
Would that record the following:
PHP Syntax (Toggle Plain Text)
  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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Mar 3rd, 2009
0

Re: simple mysql question..plz answer :)

ya ofcourse...
before executing the query.... the parser will parse the arguement... after that only the mysql_query function will execute the query...
Reputation Points: 19
Solved Threads: 3
Light Poster
vinothkumarc is offline Offline
28 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: insert csv file into mysql through php
Next Thread in PHP Forum Timeline: Using and processing XML from multiple sources





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC