Php 变量中的If语句
我看到过很多有类似问题的帖子,但我找不到一个正确的答案。 问题是我有一个代码说如果。。。是空的,使变量。。。(见下面的代码)。 这个变量是一个表单,在这个表单中,您有名称、消息等。我想要的是名称的占位符,如果用户登录成为他的名称,则该占位符将保存在我的数据库中。代码如下:Php 变量中的If语句,php,variables,if-statement,Php,Variables,If Statement,我看到过很多有类似问题的帖子,但我找不到一个正确的答案。 问题是我有一个代码说如果。。。是空的,使变量。。。(见下面的代码)。 这个变量是一个表单,在这个表单中,您有名称、消息等。我想要的是名称的占位符,如果用户登录成为他的名称,则该占位符将保存在我的数据库中。代码如下: $action = isset($_POST["action"]) ? $_POST["action"] : ""; if (empty($action)) { // Send back the contac
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) {
// Send back the contact form HTML
$output = "<div style='display:none'>
<div class='contact-top'></div>
<div class='contact-content'>
<h1 class='contact-title'>Stuur een bericht voor hulp:</h1>
<div class='contact-loading' style='display:none'></div>
<div class='contact-message' style='display:none'></div>
<br><br><form action='#' style='display:none'>
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder='Naam*' /><br><br>
<input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' placeholder='Email*' /><br><br>";
$action=isset($\u POST[“action”])$_POST[“action”]:“”;
if(空($action)){
//将联系人表单发送回HTML
$output=”
斯图尔·伊恩·贝里赫特·沃尔普:
“;
这是我想要的,但不起作用:
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder=', " if (logged_in() === true) {echo $user_data["name"] } else { echo 'Naam'; } " ,' /><br><br>
希望有人能帮忙,提前谢谢
保罗
(naam=name在我的语言中)你忘了在
中将你的if括起来,只需在文件的顶部这样做
<?php if(logged_in()==true){ $name = $user_data["name"];} else {$name="Naam*";};?>
然后在表单中回显$name
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder='<?php echo $name;?>' /><br><br>
您必须连接要放入字符串中的变量。例如,您可以执行以下操作:
if (User is logged)
naam = 'USERNAME';
else
naam = '';
在您的输出中:
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder='".$naam."' />
您应该在input@LLL我认为他更倾向于在包含html的字符串中完成,而不是在模板中。
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) {
if(logged_in()==true){ $name = $user_data["name"];} else {$name="Naam*";};
// Send back the contact form HTML
$output = "<div style='display:none'>
<div class='contact-top'></div>
<div class='contact-content'>
<h1 class='contact-title'>Stuur een bericht voor hulp:</h1>
<div class='contact-loading' style='display:none'></div>
<div class='contact-message' style='display:none'></div>
<br><br><form action='#' style='display:none'>
<input type='text' id='contact-name' class='contact-input' name='".$name."' tabindex='1001' placeholder='Naam*' /><br><br>
<input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' placeholder='Email*' /><br><br>";
if (User is logged)
naam = 'USERNAME';
else
naam = '';
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder='".$naam."' />