teisenhood Posted December 14, 2010 Share Posted December 14, 2010 what am i doing wrong? <?php $input_value = a tall order; if ( $input_value == a tall order ) { echo 'Correct!'; } if ( $input_value = err on the side of caution ) { echo 'correct!'; } else { echo 'Sorry, try again.'; } ?> also, once i get this to work i want it to be able to have the input value be a submit form in HTML so that anything the user puts in the box will go through this piece of code to decide what to do with what they put in. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/ Share on other sites More sharing options...
upp Posted December 14, 2010 Share Posted December 14, 2010 <?php $input_value = 'a tall order'; if ( $input_value == 'a tall order' ) { echo 'Correct!'; } if ( $input_value = 'err on the side of caution' ) { echo 'correct!'; } else { echo 'Sorry, try again.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147332 Share on other sites More sharing options...
Elridan Posted December 14, 2010 Share Posted December 14, 2010 @upp I may be wrong, but I think he was looking for this: <?php $input_value = 'a tall order'; if ( $input_value == 'a tall order' ) { echo 'Correct!'; } elseif ( $input_value = 'err on the side of caution' ) { echo 'correct!'; } else { echo 'Sorry, try again.'; } ?> Let us know teisenhood. As for the form part, are you posting back to the page or to another page? Either way: <form name="formName" action="page.php" method="post"> <select name="selectName"> <option value = "a tall order"> <option value = "err on the side of caution"> <option value = "Something Else"> </select> </form> ####page.php $input_value = $_GET['selectName']; ...etc. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147334 Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 @upp I may be wrong, but I think he was looking for this: <?php $input_value = 'a tall order'; if ( $input_value == 'a tall order' ) { echo 'Correct!'; } elseif ( $input_value == 'err on the side of caution' ) { echo 'correct!'; } else { echo 'Sorry, try again.'; } ?> Let us know teisenhood. One more minor error fix Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147335 Share on other sites More sharing options...
Elridan Posted December 14, 2010 Share Posted December 14, 2010 @upp I may be wrong, but I think he was looking for this: <?php $input_value = 'a tall order'; if ( $input_value == 'a tall order' ) { echo 'Correct!'; } elseif ( $input_value == 'err on the side of caution' ) { echo 'correct!'; } else { echo 'Sorry, try again.'; } ?> Let us know teisenhood. One more minor error fix Thanks for that, completely missed it. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147338 Share on other sites More sharing options...
teisenhood Posted December 14, 2010 Author Share Posted December 14, 2010 thanks, but there's another problem. even if i do something as simple as <html> <body> blah blah <?php echo 'hi'; ?> </body> </html> it doesnt show up. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147352 Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 Look at your page source in your browser - do you see the <?php ?> tags? If so, your page is not being processed as a PHP page. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147354 Share on other sites More sharing options...
teisenhood Posted December 14, 2010 Author Share Posted December 14, 2010 ya when i open it in firefox as well as google chrome it gives me exactly what i just wrote in notepad back. what can i do about that? i'm sure firefox supports php Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147359 Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 Does your web server have PHP installed? Firefox doesn't run PHP, the web server does, and then sends html to Firefox that is generated by the PHP code. If you're just loading the file on your local machine into Firefox, that won't do PHP. It has to be running on a server configured for PHP. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147363 Share on other sites More sharing options...
teisenhood Posted December 14, 2010 Author Share Posted December 14, 2010 i don't seem to remember having to install anything in the past. oh well, i feel like an idiot, but can you tell me how to go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147375 Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 Do you have your own server or are you on a hosting plan? If you're on a hosting plan, they should have PHP installed. You might be using the wrong extension (i.e. using .html instead of .php or maybe they require .php5). If you can't figure out why it's not working, you'll probably need to contact tech support to see what you're doing wrong. If you have your own server, installing PHP is a bit out of scope for this forum, it depends on the OS and whether you have packages for your distro and what not. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147380 Share on other sites More sharing options...
teisenhood Posted December 14, 2010 Author Share Posted December 14, 2010 i'm definitely using .php, but i have no idea if i'm on a hosting plan. i'm a kid with a laptop. what ever that entails. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147384 Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 So you're not uploading your files to a web server? If the address location says "file://" you won't be able to do php. You have to be connecting to a server. If your laptop is a Mac or Linux box, you can set it up on your laptop; I don't know if you can on Windows or not (you probably can install Apache and PHP but I wouldn't know anything about that). Bottom line, though, is for PHP to work it has to be running on a web server, not just loading the file into Firefox. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147386 Share on other sites More sharing options...
teisenhood Posted December 14, 2010 Author Share Posted December 14, 2010 AH! ok that makes much more sense. but, that actually brings me to another problem. i'm doing all of this for a website im making, and i ahave a program called putty to actually upload everything to the server. however, it asks for a login and password and i have no idea what that would be because i never made one. i've done this in the past but it was three or four years ago and i have since forgotten most of it. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147389 Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 AH! ok that makes much more sense. but, that actually brings me to another problem. i'm doing all of this for a website im making, and i ahave a program called putty to actually upload everything to the server. however, it asks for a login and password and i have no idea what that would be because i never made one. i've done this in the past but it was three or four years ago and i have since forgotten most of it. Yes, putty is a good SSH client. But it doesn't do a whole lot if you don't know your password. Quote Link to comment https://forums.phpfreaks.com/topic/221670-simple-if-then-statement-but-it-doesnt-work/#findComment-1147392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.