首页 \ 问答 \ 如何将PHP输入到HTML占位符?(How to input PHP into HTML placeholder?)

如何将PHP输入到HTML占位符?(How to input PHP into HTML placeholder?)

我正在尝试使用它来保存用户名,然后在下次访问时将其放入HTML占位符。 这样做最有效的方法是什么?

我搜索了其他线程并尝试使用'include'并将$ name放在输入占位符中,但它最终给我错误,因为txtName和txtAge未定义。 我不确定如何重新组织我的代码以使其正常工作。

PHP和HTML Doc#1:

    $doc = "<!DOCTYPE html>
        <html lang='en'>
        SOME HTML........
        <input type='text' name='txtName' id='txtName' placeholder='$name'>
        SOME HTML........
    </html>";

echo $doc;

PHP /文件#2:

<?php 

    $name = $_POST["txtName"];
    $age = $_POST["txtAge"];
    $k = $_POST['radRaceLength'];


    ///check if cookie exists
    if ( isset($_COOKIE["nameData"]) ){
        $name = $_COOKIE["nameData"];
    }
    else{
        $name = $name;
    }
    if ( isset($_COOKIE["ageData"]) ){
        $age = $_COOKIE["ageData"];
    }
    else{
        $age = $age;
    }
    setcookie("nameData", $name, time() + 3600, "/");
    setcookie("ageData", $age, time() + 3600, "/");

    $fiveK = 10 + ($age / 2); 
    $tenK = 18 + ($age / 3);
    $member = isset($_POST["chkMember"]) ? $fiveK = $fiveK - 5 AND $tenK = $tenK - 5: $member = NULL;

    if ( !$name AND $age <= 21 )
        echo "Please provide a name and valid age";
    else

        echo $name.', you are registered for the '.$k.' race. Your fee is: ';
        echo ( ($_POST["radRaceLength"] == "5K")? "$fiveK":"$tenK" );



?>

I'm trying to make it so a cookie saves the users name and then puts it in the HTML placeholder next time they visit. What's the most efficient way of doing this?

I searched the other threads and tried using 'include' and putting $name in the input placeholder, but it ends up giving me errors because txtName and txtAge are undefined. I'm unsure how to reorganize my code to get it working.

PHP&HTML Doc#1:

    $doc = "<!DOCTYPE html>
        <html lang='en'>
        SOME HTML........
        <input type='text' name='txtName' id='txtName' placeholder='$name'>
        SOME HTML........
    </html>";

echo $doc;

PHP/Doc#2:

<?php 

    $name = $_POST["txtName"];
    $age = $_POST["txtAge"];
    $k = $_POST['radRaceLength'];


    ///check if cookie exists
    if ( isset($_COOKIE["nameData"]) ){
        $name = $_COOKIE["nameData"];
    }
    else{
        $name = $name;
    }
    if ( isset($_COOKIE["ageData"]) ){
        $age = $_COOKIE["ageData"];
    }
    else{
        $age = $age;
    }
    setcookie("nameData", $name, time() + 3600, "/");
    setcookie("ageData", $age, time() + 3600, "/");

    $fiveK = 10 + ($age / 2); 
    $tenK = 18 + ($age / 3);
    $member = isset($_POST["chkMember"]) ? $fiveK = $fiveK - 5 AND $tenK = $tenK - 5: $member = NULL;

    if ( !$name AND $age <= 21 )
        echo "Please provide a name and valid age";
    else

        echo $name.', you are registered for the '.$k.' race. Your fee is: ';
        echo ( ($_POST["radRaceLength"] == "5K")? "$fiveK":"$tenK" );



?>

原文:https://stackoverflow.com/questions/35215190
更新时间:2022-11-30 12:11

最满意答案

Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。
HSSF - 提供读写Microsoft Excel格式档案的功能。
XSSF - 提供读写Microsoft Excel OOXML格式档案的功能。
HWPF - 提供读写Microsoft Word格式档案的功能。
HSLF - 提供读写Microsoft PowerPoint格式档案的功能。
HDGF - 提供读写Microsoft Visio格式档案的功能。

其他回答

是一种标志,    <a href="http://wenwen.soso.com/z/urlalertpage.e?sp=shttp%3a%2f%2fwww.digitalstarmap.com%2fproducts%2fpoi.html" target="_blank">http://www.digitalstarmap.com/products/poi.html</a>

相关问答

更多
  • POI是“Point of Interest”的缩写,可以翻译成“信息点”,每个POI包含四方面信息,名称、类别、经度纬度、附近的酒店饭店商铺等信息。我们可以叫它为“导航地图信息”,导航地图数据是整个导航产业的基石。 . ! 如有不懂,请追问。 !
  • 你好,很高兴回答你的问题。 POI是“Point of Interest”的缩写,中文可以翻译为“兴趣点”。在地理信息系统中,一个POI可以是一栋房子、一个商铺、一个邮筒、一个公交站等。景点POI可以理解称为感兴趣的景点。 满意请采纳谢谢~~~^ω^
  • 动漫以及游戏《舰队collection》的夕立的口癖,没有实际意义,用来卖萌的,常常在说话末尾poi一声
  • poi是什么意思[2023-08-18]

    POI   中国POI(Point of Interest)数据库   什么是POI?   POI是“Point of Interest”的缩写,可以翻译成“兴趣点”吧,每个POI包含四方面信息,名称、类别、经度、纬度。   这个计划的远景目标是建立全国的POI数据库,并且全部开放。   目前POI数据库计划已经发布有北京市区POI数据16000条,全国村镇POI数据8万余条。全国其它地区的POI数据正在搜集整理中,同时还有一个全国公路收费站POI数据的计划也在进行。   一、道路收费站标注计划   1 估 ...
  • poi是什么意思[2022-02-24]

    poi [英][pɔɪ][美][pɔɪ] n.山芋食物; 以上结果来自金山词霸 例句: 1. Integration with blackberry maps service offers a variety of app features,ranging from navigation directions to poi recommendations. 与黑莓地图服务相集成带来了从方向导航到兴趣点推荐的各式应用程序功能。 2. A gps point of interest specifies, at ...
  • 只是白露级驱逐舰“夕立”的一个口癖,由于夕立的人设很像一个小狗狗,然后就有了稳如poi的梗(三步一摔,五步一趟)
  • n. (pl. poies) (夏威夷的)芋粉酱。 1. In proc . the 2nd int . semantic web conf . , 1提出了poi的概念来定义扩展portlet的表示层特征。 2. Poi nt is , when the com pany wanted to close the facility down 问题是,当公司要关闭工厂时 3. < i > tant pis ! il ne goutera pas mes paton pois chiches . < / i > ...
  • poi是什么意思[2023-08-26]

    Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。 HSSF - 提供读写Microsoft Excel格式档案的功能。 XSSF - 提供读写Microsoft Excel OOXML格式档案的功能。 HWPF - 提供读写Microsoft Word格式档案的功能。 HSLF - 提供读写Microsoft PowerPoint格式档案的功能。 HDGF - 提供读写Microsoft Visio格式档案的 ...
  • POI是什么意思[2023-11-26]

    网页链接
  • 你说的应该是舰队收藏的 出自舰队收藏 驱逐舰·夕立 声优:谷边由美 隶属第三水雷舰队,吹雪的室友,白露级驱逐舰4号舰。 该人物基本每句话结尾都有一个poi,意义不明只是单纯口癖

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)