Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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和jQuery_Php - Fatal编程技术网

多行未插入数据库..PHP和jQuery

多行未插入数据库..PHP和jQuery,php,Php,我已经创建了动态表,从中可以向数据库中插入数据,但问题是,当我尝试向数据库中插入多行数据时,它将一无所获。因为我试着只插入一行作为它的插入成功,这告诉我我做错了什么 <?php include "includes/config.php"; ?> <?php $error_array = array(); $name = $email = $phone = $name_Error = $email_Error =$phone_Error =""; if(isset($_PO

我已经创建了动态表,从中可以向数据库中插入数据,但问题是,当我尝试向数据库中插入多行数据时,它将一无所获。因为我试着只插入一行作为它的插入成功,这告诉我我做错了什么

<?php
include "includes/config.php";
?>
<?php
$error_array = array();
$name = $email = $phone = $name_Error = $email_Error =$phone_Error ="";



if(isset($_POST['save_all']))
{   
    if($_POST['name'] !="")
    {
        $name = $_POST['name'];     
    }
    else
    {
        $name_Error ="Enter name";      
        array_push($error_array,$name_Error);       
    }


    if($_POST['email'] !="")
    {
        $email = $_POST['email'];
    }
    else
    {
        $email_Error ="Enter email";
        array_push($error_array,$email_Error);

    }


    if($_POST['phone'] !="")
    {
        $phone = $_POST['phone'];
    }
    else
    {
        $phone_Error ="Enter phone";
        array_push($error_array,$phone_Error);  
    }   


    if(count($error_array) == 0)
    {
        $insert_user = "INSERT INTO users(user_id,name,email,phone) values(NULL,'$name','$email','$phone')";        
        $res_users = mysqli_query($link,$insert_user);

        if($res_users >0)
        {
            $success_Message = "record inserted";
            array_push($error_array,$success_Message);
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<?php echo CSS_URL;?>add_more.css">
<script src="<?php echo JS_URL;?>jquery.js"></script>
<title>Add More</title>
<script>
$(document).ready(function()
{
    var count = 1;
    $(".addmore_Button").click(function()
    {
        count++;
        $(".addmore_Form_Table").append('<tr><td class="serial_num"><span>'+count+'</span></td><td><input type="text" name="name"/></td><td><input type="text" name="email"/></td><td><input type="text" name="phone"/></td><td><a href="#"><img id="delete'+count+'" style="margin-left:35px; margin-right:10px" onclick="deleteRow(this.id);" src="images/delete (1).png" /></a></tr>');
    });
});

function deleteRow(id)
{
    confirm("Are you sure you want to delete...?");
    $("#"+id).parent().parent().parent().remove();  
}


$(document).ready(function()
{
    $("#delete_User").on('click',function()
    {
        alert("Sorry, you cant delete first row...!!");
    });

});
</script>
</head>
<body>
<table class="addmore_Table">
  <tr>
    <th class="heading">Sr.No</th>
    <th class="heading">Email</th>
    <th class="heading">Name</th>
    <th class="heading">Phone</th>
    <td><input type="submit" class="addmore_Button" name="addmore_Button" value="Add More" /></td>
  </tr>
</table>
<form name="addmore_Form" action="" method="post" class="addmore_Form">
  <table class="addmore_Form_Table">
    <tr>
      <td></td>
      <td><?php echo $name_Error;?></td>
      <td><?php echo $email_Error;?></td>
      <td><?php echo $phone_Error;?></td>
      <td></td>
    </tr>
    <tr>
      <td class="serial_num"><span>1</span></td>
      <td><input type="text" name="name" value="<?php echo $name;?>" /></td>
      <td><input type="text" name="email" value="<?php echo $email;?>" /></td>
      <td><input type="text" name="phone" value="<?php echo $phone;?>" /></td>
      <td><a href="#"><img id="delete_User" style="margin-left:35px; margin-right:10px" src="images/delete (1).png" /></a></td>
    </tr>
  </table>
  <input type="submit" class="save_all" name="save_all" value="Save All" />
</form>
</body>
</html>


用户id是自动递增的吗?从insert语句中省略它,并从值中删除“NULL”。javascript
$(“.addmore\u按钮”)
正在添加与原始表单元素同名的其他表单元素。因此,只插入最后一个元素/值,因为它们将覆盖以前的元素/值。您需要给它们一个唯一的名称,或者使用一个数组名,即。
name=“name[]”
,然后在php中对它们进行循环以插入它们我做了什么@Daniel我如何循环使用php?你能给我一些想法吗?@Sean