if and else statement problem

Thread Solved

Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

if and else statement problem

 
0
  #1
Feb 3rd, 2009
in the following piece of code the else part of my if/else statements doent seem to work it just adds nothing, thanks.

btw genre is a dropbox (and yes i have added the values) and genre2 is a text box, same with the filehost and filehost2.

  1. $name = $_POST['song'];
  2. $artist = $_POST['artist'];
  3. $genre = $_POST['genre'];
  4. $genre2 = $_POST['genre2'];
  5. $filehost = $_POST['filehost'];
  6. $filehost2 = $_POST['filehost2'];
  7. $link = $_POST['link'];
  8.  
  9. if($genre="other")
  10. {$genre=$genre2;}
  11. else{$genre=$genre;}
  12.  
  13. if($filehost="other")
  14. {$filehost=$filehost;}
  15. else{$filehost=$filehost;}
  16.  
  17.  
  18. $con = mysql_connect('localhost',$username,$password);
  19. @mysql_select_db($database) or die( "Unable to select database");
  20. $sql = "INSERT INTO `songs` VALUES ('','$name','$artist','$genre','$filehost','$link')";
  21. $query = mysql_query($sql) or die('Error: ' . mysql_error());
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 110
Reputation: antwan1986 is an unknown quantity at this point 
Solved Threads: 8
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Junior Poster

Re: if and else statement problem

 
1
  #2
Feb 3rd, 2009
Hi there,

I think the problem is the syntax in those conditional statements. In PHP, one equals sign sets a variable, but in this case you're wanting to compare two variables. This is done by two equals sign and your code should be like this:

  1. if ($genre == "other") {
  2. $genre = $genre2;
  3. } else {
  4. $genre = $genre;
  5. }
  6.  
  7. if ($filehost == "other") {
  8. $filehost = $filehost2;
  9. } else {
  10. $filehost = $filehost;
  11. }
Last edited by antwan1986; Feb 3rd, 2009 at 8:55 am.
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,388
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 168
almostbob's Avatar
almostbob almostbob is online now Online
Nearly a Posting Virtuoso

Re: if and else statement problem

 
0
  #3
Feb 3rd, 2009
both else statements are redundant
else
blue = blue
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Re: if and else statement problem

 
0
  #4
Feb 3rd, 2009
Thanks antwan that was the problem.
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC