if-statement

PHP if not statements

醉酒当歌 提交于 2020-06-07 04:01:43
问题 This may be the way my server is set up, but I'm banging my head against the wall. I'm trying to say that if $action has no value or has a value that is not "add" or "delete" then have an error, else keep running the script. However, I get an error no matter what $action is. $action = $_GET['a']; if((!isset($action)) || ($action != "add" || $action != "delete")){ //header("location:index.php"); echo "error <br>"; } $action is being set properly and if run something like if($action =="add") it

Why is my “if” condition (string comparison) always true?

百般思念 提交于 2020-06-03 07:57:27
问题 In the following example, I find that the if [ $aaa==x ] condition is always true. for aaa in {x,y} do echo --------- echo $aaa; if [ $aaa==x ] then echo this is x elif [ $aaa==y ] then echo this is y fi echo $aaa; done; That is, I always get the output as: --------- x this is x x --------- y this is x y Even if I replace == with = , the problem remains. Why? 回答1: When you do: if [ $aaa==x ] You are expanding the parameter $aaa, then concatenating two = and the letter x , then testing whether

Submit button takes 2 clicks to call function in React

a 夏天 提交于 2020-05-31 04:23:10
问题 When i'm clicking submit button it requires to clicks to properly fire off the function. I didn't have problem before implementing if statements. Does it have something with fact that i have 2 if statements inside and after each click it checks only 1 if statement? onSubmit = (e) => { const { firstName, lastName, email, eventDate, validation} = this.state if (firstName, lastName, eventDate, email) { this.setState({validation: true}) if (new RegExp(/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,15}/g)

IF statement problem about a small converter I made

谁说我不能喝 提交于 2020-05-30 04:09:27
问题 I am making a program that converts your weight from kg to lbs and vice versa. It prompts you to input a weight, asks if it's in kg or lbs, then gives you the result. The code is as follows: weight = int(input("What is your weight? ")) unit = input ("(L)bs or (K)g? ") unit = unit.upper if unit == "L": converted = (weight * 0.45) print(converted) else: converted = (weight // 0.45) print(converted) The converter is working fine if I put my kg and say it's kg, but when I put my weight in lbs and

Using ifelse in R when one of the options produces NAs?

与世无争的帅哥 提交于 2020-05-29 10:21:11
问题 I want to vectorize a function that relies on checking a condition and depending on whether this condition is TRUE or FALSE, return the outcome of one of two functions, respectively. The problem is that, when the condition is FALSE, the first function cannot be evaluated. Then, ifelse returns the correct values but it also produces a warning. I would like to produce a function that does not produce warnings. I have tried ifelse() , but it does not work. I was expecting that this command would

How can you make the previous line disappear in python?

泪湿孤枕 提交于 2020-05-24 03:41:06
问题 I'm making a constellation that starts from (0,0). The previous line has to disappear after a two second delay and when the left is clicked within the two second delay, white circles should appear. I don't know why my timer isn't working and I'm not sure how to make the line disappear. Also the circles don't appear. This is my code from pygame import * import random init() size = width, height = 700, 700 screen = display.set_mode(size) button = 0 BLACK = (0, 0, 0) GREEN = (0, 255, 0) RED =

how to check if number begins with “+” in excel?

左心房为你撑大大i 提交于 2020-05-17 08:49:29
问题 I need to check if a number begins with "+" or "00" or "(" but when I try with this formule: =IF(LEFT(E4="+",1),1,0) I get an error #VALUE 回答1: Try to include OR logic including a wildcard in a COUNTIF and use that in an IF : =IF(SUM(COUNTIF(E2,{"+*","(*","00*"})),"This","That") If you got leading spaces in front of the + then just add a space before the criteria. I guess you could also add another criteria like " +* . Unfortunately TRIM() won't work within a COUNTIF . 来源: https:/

If condition over a vector in R

*爱你&永不变心* 提交于 2020-05-17 06:15:11
问题 I am quite new to this kind of function in R. What I am trying to do is to use the if statement over a vector. Specifically, let's say we have a vector of characters: id <- c('4450', '73635', '7462', '12') What I'd like to do is to substitute those elements containing a specific number of characters with a particular term. Here what I tried so far: for (i in 1:length(id)) { if(nchar(i) > 3) { id[i] <- 'good' } else id[i] <- 'bad' } However, the code doesn't work and I don't understand why.

Registry class. If key exist

社会主义新天地 提交于 2020-05-17 03:01:01
问题 Im using the Microsoft.Win32.Registry class. Im trying to make a if RegKey exist statement but don't know how I want something like this: RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\test"); if(key.keyExist("yourKey")) Console.WriteLine("yourKey exist!"); 回答1: As far as I know, the SubKey is stored in a path in the system. So you can do something like this to check out if the SubKey exists: using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test")) { if (key

Registry class. If key exist

别来无恙 提交于 2020-05-17 03:00:35
问题 Im using the Microsoft.Win32.Registry class. Im trying to make a if RegKey exist statement but don't know how I want something like this: RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\test"); if(key.keyExist("yourKey")) Console.WriteLine("yourKey exist!"); 回答1: As far as I know, the SubKey is stored in a path in the system. So you can do something like this to check out if the SubKey exists: using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test")) { if (key