[英]If/Else statement using PHP?
I am trying to do a survey and based on people's answers I want to return an answer.我正在尝试进行一项调查,并根据人们的回答我想返回一个答案。 I am using PHP to use the If/Else statement, and I am very new to PHP.我正在使用 PHP 来使用 If/Else 语句,我对 PHP 非常陌生。 Since PHP is pretty similar to Javascript with the If/Else statements, besides the $ sign, I was attempted doing a function with a getelement.byid() inside of it, but seem to be getting a syntax error and can't figure out what that is.由于 PHP 与带有 If/Else 语句的 Javascript 非常相似,因此除了 $ 符号之外,我还尝试在其中执行一个带有 getelement.byid() 的函数,但似乎遇到了语法错误并且无法弄清楚那是什么。 Here is the code:这是代码:
<?php
function order()
{
if $doc->getElementById(ball) then
{print "you chose ball";
}
}
?>
the error I get is in the if $doc->getElementById(ball) then line.我得到的错误是在if $doc->getElementById(ball) then行中。 This is a PHP page on its own that is called from an HTML page.这是一个 PHP 页面,它本身是从 HTML 页面调用的。 I'm sure it's something minor, but does anyone have an idea on what's missing/wrong with that line?我确定这是小事,但有没有人知道那条线有什么遗漏/错误?
This is just basic syntax.这只是基本语法。 You don't have parentheses around the condition:条件周围没有括号:
if (condition){
//do something
}
if ($doc->getElementById(ball)){
print "you chose ball";
}
Here's the documentation on the if statement这是有关 if 语句的文档
<?php
function order()
{
if ($doc->getElementById(ball))
{
print "you chose ball";
}
}
?>
There are several errors with your code, I will list them in comments:你的代码有几个错误,我会在评论中列出:
<?php
function order()
{
// Missing opening/closing parentheses (); no "then" in php.
if ($doc->getElementById(ball))
// Where are you referencing $doc from? Unlike javascript, php does not have built-in DOM manipulation.
{print "you chose ball";
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.