Jump to content

Simple If Then Statement, but it doesn't work


teisenhood

Recommended Posts

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!

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.