php中的按钮在while循环中时如何给出规范 [英] how to give specification for button in php when it is in while loop

查看:50
本文介绍了php中的按钮在while循环中时如何给出规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
echo "<html><form name=form1 method=post>";
$c = mysql_connect("localhost","root","");
mysql_select_db("test", $c);
$query = mysql_query("select * from age");
while ($s = mysql_fetch_row($query))
{
    echo "<table><tr><td>Name   :<textarea rows=5 cols=5 name=name>$s[0] </textarea></td></tr><tr><td>Age   :<textarea rows=5 cols=5 name=age>$s[1] </textarea></td></tr><tr><td><input type=submit value='click' name=submit></td></tr></table>";
}
if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    $age = $_POST['age'];
    echo "name is $name"." age is $age";
}
echo "</form></html>";
?>

在测试表中,有 4 个条目,其中包含姓名和年龄....我正在获取该姓名和年龄并将其放入 textarea 中,然后我为每个表创建了一个按钮...同时单击该按钮我得到了数据库中的最后一个条目..但我想要相应的姓名和年龄..请帮帮我

here in the test table there are 4 entries present with name and age.... I am fetching that name and age and putting that in textarea and I created one button for each table.. while click that button I am getting last entry in database.. but I want corresponding name and age.. please help me

推荐答案

目前,您正在为所有条目使用一个大的

元素.发送该表单时,实际值会被多次覆盖,而您只会看到最后一个.

Currently you are using one big <form> element for all your entries. When sending that form, the actual values get overridden many times and you just see the last one.

为了解决这个问题,你可以,例如,用这样的每个条目制作一个表格:

To solve this, you could, e.g., make a form out of every entry like this:

echo "<html>";

$c = mysql_connect("localhost", "root", "");
mysql_select_db("test", $c);
$query = mysql_query("select * from age");

while ($s = mysql_fetch_row($query))
{
    echo "<form method=post><table><tr><td>Name   :<textarea rows=5 cols=5 name=name>$s[0] </textarea></td></tr><tr><td>Age   :<textarea rows=5 cols=5 name=age>$s[1] </textarea></td></tr><tr><td><input type=submit value='click' name=submit></td></tr></table></form>";
}

if (isset($_POST['submit']))
{
    $name = $_POST['name'];
    $age=$_POST['age'];
    echo "name is $name";
    echo "age is $age";
}
// ... rest of the code ...

无论如何,您使用的 mysql 函数已被弃用.看看 PDOmysqli 作为替代!

Anyway, the mysql functions, you use, are deprecated. Have a look at PDO or mysqli as a replacement!

这篇关于php中的按钮在while循环中时如何给出规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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