Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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
Javascript 如何使用提交按钮更新mysql数据库_Javascript_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Javascript 如何使用提交按钮更新mysql数据库

Javascript 如何使用提交按钮更新mysql数据库,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,当我点击更新功能时,您如何更新mysql数据库。我要更新的字段位于我创建的文本字段中 <script> function yourfunction() { document.getElementById("name").readOnly = true; document.getElementById("number").readOnly = true; document.getElementById("st

当我点击更新功能时,您如何更新mysql数据库。我要更新的字段位于我创建的文本字段中

<script>

     function yourfunction() 
     {
         document.getElementById("name").readOnly = true;
         document.getElementById("number").readOnly = true;
         document.getElementById("status").readOnly = true;
         document.getElementById("expertise").readOnly = true;
         document.getElementById("remark").readOnly = true;

     }

    window.onload = yourfunction;

    function myfunction()
    {
        document.getElementById("name").readOnly = false;
        document.getElementById("number").readOnly = false;
        document.getElementById("status").readOnly = false;
        document.getElementById("expertise").readOnly = false;
        document.getElementById("remark").readOnly = false;
        document.getElementById("edit").style.visibility='hidden';
    }

函数yourfunction()
{
document.getElementById(“名称”).readOnly=true;
document.getElementById(“number”).readOnly=true;
document.getElementById(“status”).readOnly=true;
document.getElementById(“专家”).readOnly=true;
document.getElementById(“备注”).readOnly=true;
}
window.onload=您的函数;
函数myfunction()
{
document.getElementById(“名称”).readOnly=false;
document.getElementById(“number”).readOnly=false;
document.getElementById(“status”).readOnly=false;
document.getElementById(“专家”).readOnly=false;
document.getElementById(“备注”).readOnly=false;
document.getElementById(“编辑”).style.visibility='hidden';
}

所以首先我可以点击编辑按钮,这样我的文本字段就可以被编辑了。编辑完这些字段后,我可以单击update按钮来更新mysql数据库中的这些字段

    <?php
    $name = $_GET['name'];

    $connect = mysqli_connect("localhost", "root", "","test1");
    $output='';
    $sql = "SELECT Name, Number, Expertise, Status, Remarks FROM particulars WHERE Name ='". $name."'";

    $result = mysqli_query($connect, $sql);

    while($row= mysqli_fetch_array($result))
{
    $name = $row['Name'];
    $number =$row['Number'];
    $Expertise =$row['Expertise'];
    $status =$row['Status'];
    $remarks =$row['Remarks'];
} 

    echo "<label>Name</label> <input id = 'name' type='text' value='" .$name. "'/> <br>";
    echo "<label>Number</label><input id = 'number' type='text' value='" .$number. "'/><br>";
    echo "<label>Expertise</label><input id = 'expertise' type='text' value='" .$Expertise. "'/><br>";
    echo "<label>Status</label><input id = 'status' type='text' value='" .$status. "'/><br>";
    echo "<label>Remarks</label><input id = 'remark' type='text' value='" .$remarks. "'/><br>";
    ?>

<br><br><br>
<input type="button" id="edit" value = "Edit" onclick="myfunction()">
<input type="submit" id="update" value = "Update">
试试这个:

UPDATE particulars SET Name = $name, Number = $number, Expertise = $expertise, Status = $status, Remarks = $remarks WHERE Name = $name;

首先是while循环中的一个注释,它将通过所有行。在你的情况下,应该只有一个。这是可行的,因为只有一行,但您应该使用不应该使用while循环的方法

回到你的任务。您需要一个表单(最简单的方式)

将名称作为主键是极为无效的。数字更容易处理,更不用说多个人可以有相同的名字

将Id作为主键,并将其设置为自动增量

您可以像这样将其添加到表单中

<input name = 'id' type='hidden' value='" .$id. "'/>


使用
更新
sql查询。@是的,我知道我必须使用更新sql查询。但我不确定如何将这些文本框分配给sql查询语句。我是否使用$邮政?对不起,我对这件事很陌生。谢谢你的帮助!:)您没有表单,因此我不知道如何将字段数据发送回服务器。如果我是您,我会使用准备好的语句来防止SQL注入。尝试PDO而不是mysqli
$sql = "Update particulars  set Number = " .$_POST['number'] etc....
<input name = 'id' type='hidden' value='" .$id. "'/>