Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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_Javascript_Html_Mysql_Ajax - Fatal编程技术网

Php 当用户更新文本框值时更新mysql

Php 当用户更新文本框值时更新mysql,php,javascript,html,mysql,ajax,Php,Javascript,Html,Mysql,Ajax,我想在更正或更新表单中将值更新为学生更改值。 直到我知道,我能够在使用ajax和json从数据库下拉列表中选择名称的基础上,在文本框中获取和显示值。但当我尝试更新数据库时,它不起作用 HTML: <select name="u_stu" id="u_stu" onchange="show(this.value);" style="float:right; height:30px; width:180px;"> <option selected="selected

我想在更正或更新表单中将值更新为学生更改值。
直到我知道,我能够在使用ajax和json从数据库下拉列表中选择名称的基础上,在文本框中获取和显示值。但当我尝试更新数据库时,它不起作用

HTML:

<select name="u_stu" id="u_stu" onchange="show(this.value);" style="float:right; height:30px; width:180px;">
        <option selected="selected" disabled="disabled">Choose</option>
        <option>stu1</option>
        <option>stu2</option>
        <option>stu3</option> 
</select>
 name: <input type="text" id="name" name="name" style="float:right; height:20px; width:200px;"/><br /><br />
 age:   <input type="text" id="age" name="age" style="float:right;  height:20px; width:200px;" /><br /><br />
 phone: <input type="text" id="phone" name="u_ver_txt" style="float:right;  height:20px; width:200px;" /><br /><br />
 address:    <input type="text" id="add" name="add" style="float:right;  height:20px; width:200px;" /><br /><br />
 hobby:   <input type="text" id="hobby" name="hobby" style="float:right;  height:20px; width:200px;" /><br /><br />
 <input type="submit" value="Submit" name="u_s2" id="u_s2" style="position:relative; top:-180px; "/>

选择
斯图1
斯图2
斯图3
名称:

年龄:

电话:

地址:

爱好:

MYSQL PHP

<?php           
        $c=mysql_connect("localhost","abc","xyz");
        mysql_select_db("root");
            if(isset($_POST['u_s2']))
    {
        $name=$_POST["name"];
        $age=$_POST["age"];
        $phone=$_POST["phone"];
        $address=$_POST["address"];
        $hobby=$_POST["hoddy"];
            $id=$_POST["u_id"];
        $q2="UPDATE student SET 
                    name=$name,age=$age,phone=$phone,address=$address,hobby=$hobby WHERE Sr. no=$id";
                    mysql_query($q2);
            }
?>

您需要这样的东西:

$q= "update student set name = '".$name."', age = '".$age."', phone = '".$phone."', address = '".$address."', hobby = '".$hobby."' WHERE user = 'the user id'";
您应该像上面的示例一样使用WHERE语句,以便确保您正在更新正确的行

您还应该考虑使用MySQL LRealOracle EXECUEL字符串函数:

$name = mysql_real_escape_string($_POST['name']);

如果这是一个更新表单,您还应该在输入字段等中包含
,以便他们看到值并更新所需内容


我还建议您使用
mysqli函数
而不是
mysql函数
,因为
mysql
不再受支持和反对。

我在您的代码中没有看到任何更新语句。您不能混合使用POST&GETITS仍然无法运行@Simon\u eQadd
或死亡(mysql\u error())
并打开错误报告,让您更好地了解发生了什么。这看起来无效
,其中Sr.no=$id