2016-01-15 41 views
-4

是否可以将php值转换为表单标签?目前我只能回显到用户可编辑的文本框,但我希望它不能像标签一样编辑,我可以这样做吗?我可以将php值转换为形式吗?

下面是文本框是能够工作

<input style="color:#000000" type="text" value="<?php echo $account['Username']; ?>" name="name" required/> 

我试着在标签,但在我的web

<label for="fullname"><?php echo $account['Fullname']; ?></label> 
+0

确定您回声别的方式。你试过了吗? –

+0

你是说你想要文字在输入内,但不可编辑? HTML5'placeholder'属性可能就是您要查找的内容。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input –

+0

**你想要在表单标签中回显什么**?答案是肯定的,但我们需要澄清你想要做什么。 –

回答

1

使用echo语句上什么都没有回音。像这样:

<label><?php echo ("this is a label");?></label> 
+0

这个解决方案有什么问题,这是您的问题的最佳解决方案。 –

+0

我看不出这有什么问题。问题不明确,但这是一个非常直接的答案。 –

+0

你的代码只能工作,如果它是自我类型“这是一个标签”,但它不会工作,如果我尝试从mySQL回声<?php echo $ account ['Fullname']; ?> – whatever

0

当然这是可能的。

您可以使用之前使用过的回声函数。

确保:

  1. 你正在使用PHP文件(* .PHP)
  2. 指数在数组不为空
  3. 您使用<? php标记

尝试这种情况:

// index.php 
<?php 
$text = "privet"; 
?> 

<label for="fullname"><?php echo $text; ?></label> 
// output is <label for="fullname">privet</label> 
  • 阅读本http://php.net/manual/en/function.echo.php
  • 小心,并且还读取此http://php.net/manual/en/function.htmlspecialchars.php
  • 顺便说一句:如果它仍然无法正常工作...只是使用dump来获取变量信息

    <label><?php echo $var; ?></label> // does not working 
    // ok -> then dump the var! 
    <?php var_dump($var); ?> // hmm.. lets see (maybe null or string(0)?) :-) 
    
    相关问题