【发布时间】:2018-03-14 19:37:16
【问题描述】:
我有以下 PHP 代码
<form action="admin.php" method="post">
<?php
$conn=mysqli_connect("localhost","root","vravi","mrconnect");
if(!$conn)
{
echo "error establishing the connection";
}
$sql="select UserID,UserEmail from Users order by UserID";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0)
{
while($row=mysqli_fetch_assoc($result))
{
echo $row["UserID"];
echo $row["UserEmail"]." ".'<input type=\"text\" name=\"name[]\"/>'."</br>";
}
echo '<button type=\"submit\" name=\"submit\" value=\"submit\">'.Submit.'</button></br>';
}
?>
</form>
在浏览器中给出以下输出。
现在我有两个问题。
1)当我尝试在其中一个文本框中插入一些值并单击底部的提交按钮时,这些值没有被提交。
下面是我的 admin.php php 文件。
<?php
if(isset($_POST['submit']))
{
echo "submitted";
}
else
{
echo "not submitted";
}
?>
2)现在第二个问题是,我也希望通过表单提交我的电子邮件 ID,但这只是普通文本,谁能告诉我该怎么做?
【问题讨论】:
-
@Rizier123
button很好,只要type是submit。 -
我认为转义字符串会导致提交按钮出现问题,
-
为您的
<input>添加一个名称属性,并通过使用数组,您可以使用电子邮件 ID 作为键 -'<input type="text" name="name['.$row["UserID"].']">';然后在 php 中您可以执行foreach($_POST['name'] as $UserID => $value) -
@Sean: 有一个
name属性,它前面有很多空格:) -
@LinkinTED 很好。从来没有想过你需要滚动那么远才能看到输入的其余部分