简体   繁体   中英

php code within value attribute for html

I have a html form with a textbox in which i want to pull the name of the person signed in to automatically be filled in the text box when the page loads. below is the code i am using.

 <input type="text" autocomplete="off" name="createdby" id="createdby" value= <?= $first_name.' '.$last_name ?> readonly>

the issue is with the php code

 <?= $first_name.' '.$last_name ?>

Because of the space between .' ' . the last name does not show. however when i remove the space both the first name and the last name show but without any spaces. How do i pull both names from the database and have them separated

您应该在 php 标签周围使用双引号。

我相信它需要如下所示:

<...value="<?= $first_name.' '.$last_name ?>" readonly>

implode()看起来比这样的连接更好:

implode(' ', array($first_name, $last_name));

Convert this:

<?= $first_name.' '.$last_name ?>

Into this:

<?php echo $first_name.' '.$last_name ?>

Or this if you want to simplify variables concatenation:

<?php echo “$first_name $last_name” ?>

Use the standard php tags and explicitly echo your values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM