动态地,命名PHP中的表单元素 [英] Dynamically, naming form elements in PHP

查看:111
本文介绍了动态地,命名PHP中的表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个简单的程序,它与xampp phpmyadmin有些相似,其中创建数据库,创建表结构是使用表单动态创建的。我试图让它们的名字变成动态的,这样我就可以循环它们。

 <?php $ b = 1; ?> 

字段:< input name =field $ btype =text/>< / br>

当我提交表单时,表单的值为null。下面是表单填充后的代码

  $ a = 1; 

$ tblField = $ _POST ['field $ a'];

echofield name:。$ tblField;

输出是

 字段名称:

我不知道我做的是对的,在表单中使用变量。但是这是我认为我可以这样做的唯一方法,以便我可以创建表列动态..

解决方案

什么是字段中的 $ 字段:< input name =field $ btype =text/>< / br> ??如果您要在输入名称的字段中包含美元符号 $ ,那么整个代码必须封装在php标签中。

是这样的:<?='字段:< input name =field $ btype =text/><<< ; / BR>'; ?> 否则,它将无法工作


I wil create a simple program that is somewhat similar to xampp phpmyadmin wherein the creation of database, creation of table structure is dynamic using forms. I tried to make their names dynamic so that i could loop them.

<?php $b =1; ?>

Field:<input name="field$b" type="text" /></br>

When i submit the form, the value of the form is null. Here's the code after the sumbitting of form

    $a = 1;

    $tblField = $_POST['field$a'];

    echo "field name : ".$tblField;

The output is

field name : 

I'm not sure if what i did is right, in using a variable in the name of forms. but that is the only way i think i could do so that i could make the creation of table columns dynamic..

解决方案

What is the $ doing in Field:<input name="field$b" type="text" /></br> ?? If you are going to include the dollar sign $ in your input name's field, then the whole code must be encapsulated in the php tags.

like this: <?= 'Field:<input name="field$b" type="text" /></br>'; ?> otherwise, it won't work

这篇关于动态地,命名PHP中的表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆