Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法将表单数据提交到mysql_Php_Mysql - Fatal编程技术网

Php 无法将表单数据提交到mysql

Php 无法将表单数据提交到mysql,php,mysql,Php,Mysql,我无法在php文件中获取变量。Echo没有返回任何内容,我无法进行查询。 请帮帮我。我知道很少有愚蠢的错误,但我真的厌倦了去寻找它 我有一张表格: <form align="center" method="POST" action="saveuser.php"> <small>Choose person:</small> <select name="user" id="user" size="1" onchange="loadUserData()">

我无法在php文件中获取变量。Echo没有返回任何内容,我无法进行查询。 请帮帮我。我知道很少有愚蠢的错误,但我真的厌倦了去寻找它

我有一张表格:

<form align="center" method="POST" action="saveuser.php">
<small>Choose person:</small>
<select name="user" id="user" size="1" onchange="loadUserData()">
    <option>Please select</option>
    <?php
        $con = mysql_connect('localhost', 'root', '');
        if (!$con) {
            die('Connection error: ' . mysql_error());
        }
        echo 'Connection Success';
        mysql_select_db("live", $con);

        $sql_query="SELECT name,id FROM res1";
        if(!mysql_query($sql_query, $con))
        {
            die('INSERT Error: ' . mysql_error());
        }
        $query = mysql_query($sql_query, $con);
        $max_row=0;

        while ($row = mysql_fetch_assoc($query)){
            if ($max_row !=0){
                echo "<option value={$row[id]}>{$row[name]}</option>";
            }
            $max_row=1;
        }

        mysql_close($con);
    ?>
</select></br>
<input id="id" type="hidden"/>
<small>Name: </small><input id="name" type="text" size="40" /> 
<small>Nat: </small><input id="nat" type="text" size="30" />
<small>Licence: </small><input id="licence" type="text" size="10" /></br>
<small>R1: </small><input id="r1" type="text" size="5" />
<small>R2: </small><input id="r2" type="text" size="5" />
<small>R3: </small><input id="r3" type="text" size="5" />
<small>R4: </small><input id="r4" type="text" size="5" />
<small>R5: </small><input id="r5" type="text" size="5" />
<small>R6: </small><input id="r6" type="text" size="5" />
<small>R7: </small><input id="r7" type="text" size="5" /></br>
<small>FO1: </small><input id="f1" type="text" size="5" />
<small>FO2: </small><input id="f2" type="text" size="5" />
<small>FO3: </small><input id="f3" type="text" size="5" /></br>
<button type="submit" name="submit">Save</button>
和php文件saveuser.php:

<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
    die('Connection error: ' . mysql_error());
}
//echo 'Connection Success';
mysql_select_db("live", $con);

$id = $_POST["id"];
$name = $_POST["name"];
echo $id;
echo $name;

$sql_query="UPDATE res1 SET name='".$name."' WHERE id='".$id."'";
//,nat,licence,r1,r2,r3,r4,r5,r6,r7,f1,f2,f3 FROM res1 WHERE id='$value'";
$query = mysql_query($sql_query, $con);

mysql_close($con);

//$URL="edit.php";
//header ("Location: $URL");

?>

这是因为您没有设置字段的名称,id不会替换名称:


您没有为输入提供名称属性

您的$\u POST数组将只包含包含的值。

请尝试输入提交

<input type="submit" value="Submit" />
然后关闭窗体


并给输入命名

我试图运行php文件。没有错误。但是echo$id;不返回任何内容..您的查询可能不会返回任何内容,因此,这将是第一位。。检查您创建的查询字符串,自己在mysql中运行,看看结果是什么。ID没有值。。。你只要把它设为。。你期望它有什么价值?它不是name=id吗?id不能代替表单输入的name;另一方面,对于锚而言,它是一个替代品;也许OP对这个事实有点困惑;
<input type="submit" value="Submit" />