| | |
if and else statement problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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.
btw genre is a dropbox (and yes i have added the values) and genre2 is a text box, same with the filehost and filehost2.
php Syntax (Toggle Plain Text)
$name = $_POST['song']; $artist = $_POST['artist']; $genre = $_POST['genre']; $genre2 = $_POST['genre2']; $filehost = $_POST['filehost']; $filehost2 = $_POST['filehost2']; $link = $_POST['link']; if($genre="other") {$genre=$genre2;} else{$genre=$genre;} if($filehost="other") {$filehost=$filehost;} else{$filehost=$filehost;} $con = mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $sql = "INSERT INTO `songs` VALUES ('','$name','$artist','$genre','$filehost','$link')"; $query = mysql_query($sql) or die('Error: ' . mysql_error());
My Sites: SlickTunes and Loved By Design
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:
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:
PHP Syntax (Toggle Plain Text)
if ($genre == "other") { $genre = $genre2; } else { $genre = $genre; } if ($filehost == "other") { $filehost = $filehost2; } else { $filehost = $filehost; }
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
both else statements are redundant
else
blue = blue
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
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
![]() |
Similar Threads
- insert statement problem (C#)
- WHERE statement problem. (PHP)
- Problem kicking my but!!! can anybody help? (C++)
- implement semaphore without the use of while or any if statement (C)
- Simple If statement questions (Java)
- If statement problem (Java)
- CardLayout problem restated (Java)
Other Threads in the PHP Forum
- Previous Thread: Object Persistence?
- Next Thread: PHP files not dispalying in browser
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube






