不会将多行插入到database..PHP和jQuery中

时间:2016-04-15 17:34:03

标签: php

我已经创建了动态表,我可以将数据插入到数据库中,但问题是,当我尝试在数据库中插入多于一行时,它无处可去。因为我试图插入只有1行作为插入成功,这告诉我我做错了什么

<?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>

0 个答案:

没有答案