473,320 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why is if else statement not working

29
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. fwrite(STDOUT, "do you want ans in cel ? type y or N to continue \n");
  5. //$handle = fread(STDIN, 80);
  6. $ansincel =fgets(STDIN);
  7. echo " Plz enter number \n";
  8. //$handle1 = fread(STDIN, 80);
  9. $numdeg = fgets(STDIN);
  10.  
  11. if ($ansincel = 'y')
  12. {
  13.     $tc = ((5/9)*($numdeg - 32)); // convert to degrees celcius
  14.     fwrite(STDOUT, " the degree in cel is $tc ");
  15. else
  16. {
  17.     $tf = ((9/5)*($numdeg + 32));   // convert to degrees fahrenheit
  18.     fwrite(STDOUT, " the degree in far is $tf ");
  19. }
  20. ?>
Jun 30 '10 #1

✓ answered by Niheel

change

Expand|Select|Wrap|Line Numbers
  1. if ($ansincel = 'y')
to

Expand|Select|Wrap|Line Numbers
  1. if ($ansincel == 'y')

5 1518
Niheel
2,460 Expert Mod 2GB
change

Expand|Select|Wrap|Line Numbers
  1. if ($ansincel = 'y')
to

Expand|Select|Wrap|Line Numbers
  1. if ($ansincel == 'y')
Jun 30 '10 #2
dragrid
29
@kub365
Kub 365 Much appreciated
Jun 30 '10 #3
dragrid
29
Anyone,
Trying to find out why when i made change above ( from = 'y' to == 'y' ) it skips the if solution and keep executing the else portion
Jul 1 '10 #4
nathj
938 Expert 512MB
I might be missing something but perhaps it should do that. It may be worth changing your if condition to enforce case on both sides of the operator:
Expand|Select|Wrap|Line Numbers
  1. if (strtoupper($ansincel) == 'Y')
  2.  
then you have ruled out any case issues. If you are still not sure what is going on throw in some echo statements just before the if:
Expand|Select|Wrap|Line Numbers
  1. echo("ansincel in upper case =" . strtoupper($ansincel));
  2.  
This will show what the value is before you run your conditional statement.
Hope that helps you out.
nathj

PS If you want more output without having to echo variables all over the place you could write them to a log file. I've got a class that will do that if you need it.
Jul 1 '10 #5
Dormilich
8,658 Expert Mod 8TB
it may happen, that hitting enter does not only submit the input, but also appends a line feed character, thus your string would be "y\n", which doesn’t match "y".

try var_dump($ansincel); to check the variable’s content.
Jul 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Drew | last post by:
I am building an application for keeping track of user permissions here at work. I have built the interfaces, and am now working on the processing page for inserting to the database. I am having...
3
by: Athmaus | last post by:
Hello, I have this ecom page that i am making where customers can select to choose additional licenses before they purchase. I have that part working with javascript. Problem is that when the...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
31
by: ajos | last post by:
hi frnds, i have a form,which has 2 input text boxes, the values are entering the text boxes,when i leave the 2 text boxes blank and hit submit a java script gives the message that the 2 fields are...
3
by: BibhuAshish | last post by:
Hello guys i have one function which converts the ip/netmask into networkid/netmask and also it shows the message to user that his ip is changed to network id. but that function is working in...
2
by: kigoobe | last post by:
I am having a very weird issue here, a simple form submit not working. Trying for several hours now ... must be something stupid ... help appreciated. First, the html - <form id="formFinale"...
7
by: Ja NE | last post by:
(as first - thank you for all your help several years ago, and second - please apologise me for my clumsy enlgish) so, preface: some users on my photo related site sometimes enter (link) giant...
1
by: filch | last post by:
Hi, I am new to this forum ... so hello to all! I am trying to get a script working which will show or hide a table based on a user checking or unchecking a parent checkbox. This is the...
2
by: anandjuventus | last post by:
function VisibleDiv(obj) { if (obj == BaseLog) { var objStyle = document.getElementById('DivCalls').style; if (objStyle.display == "block") ...
12
by: flower88 | last post by:
Hello, I'm working on a search form. I have 3 combo boxes and I want to find combinations on a query to later show it in a report. Perhaps this is too complicated but I don't know how else to do it....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.