Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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 我尝试在数据库中插入值,但没有使用axaj、jquery在数据库中插入值_Php_Jquery_Ajax - Fatal编程技术网

Php 我尝试在数据库中插入值,但没有使用axaj、jquery在数据库中插入值

Php 我尝试在数据库中插入值,但没有使用axaj、jquery在数据库中插入值,php,jquery,ajax,Php,Jquery,Ajax,我尝试在db中插入值 $cn = mysqli_connect("localhost","root","","testajax") or die("Opps some thing went wrong"); if(isset($_POST['bottonsave'])) { $sql = "insert into tableajax (studentname,gender,phone) values ('{$_POST[studentname]}','{$_POST[gender]}',

我尝试在db中插入值

$cn = mysqli_connect("localhost","root","","testajax") or die("Opps some thing went wrong");
if(isset($_POST['bottonsave']))
{
    $sql = "insert into tableajax (studentname,gender,phone) values ('{$_POST[studentname]}','{$_POST[gender]}','{$_POST[phone]}')";
    $result = mysqli_query($cn,$sql);
    if($result == false)
    {
        echo 'error - ';
        echo mysqli_error($cn);
    }
    else
    {
        echo "all good'";
    }
}

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

    <div id ="testforajax">
         <tr>
               <td>StudentName </td>
               <td>:</td>
               <td><input type ="text" id ="studentname" name ="studentname" >
               </td>
               </tr>

                <tr>
               <td>gender </td>
               <td>:</td>
               <td><input type ="text" id ="gender" name ="gender" >
               </td>
               </tr>

                <tr>
               <td>Phone </td>
               <td>:</td>
               <td><input type ="text" id ="Phone" name ="Phone" >
               </td>
               </tr>

                 <input type="button" value ="save" id ="save">
                 </div>
      <script type="text/javascript">
     $(function(){
        // create ajax insert record
        $("#save").click(function(){

        var namestudent = $('#studentname').val();
        var genderstudent  = $('#gender').val();
        var phonestudent = $('#phone').val();
        $.ajax({
                url : "index.php",
                type: "POST",
                async: false,
                data: {
                       buttonsave : 1,
                       studentname : namestudent,
                       gender : genderstudent,
                       phone : phonestudent
                },
                success: function(result)
                {
                    alert("success");
                }
              });

        });
    });

 </script>     
$cn=mysqli_connect(“localhost”、“root”、“testajax”)或die(“Opps某些事情出错”);
如果(isset($_POST['bottonsave']))
{
$sql=“将值({$\u POST[studentname]},{$\u POST[gender]},{$\u POST[gender]},{$\u POST[phone]}”)插入到表ajax(studentname,gender,phone)中”;
$result=mysqli\u查询($cn,$sql);
如果($result==false)
{
回显“错误-”;
echo mysqli_错误($cn);
}
其他的
{
呼应“一切都好”;
}
}
学生姓名
:
性别
:
电话
:
$(函数(){
//创建ajax插入记录
$(“#保存”)。单击(函数(){
var namestudent=$('#studentname').val();
var genderstudent=$('#gender').val();
var phonestudent=$('#phone').val();
$.ajax({
url:“index.php”,
类型:“POST”,
async:false,
数据:{
按钮保存:1,
学生姓名:namestudent,
性别:性别学生,
电话:电话学生
},
成功:功能(结果)
{
警惕(“成功”);
}
});
});
});

您的
尝试放置控制台.log(结果);在成功代码块中,查看发生了什么。另请参阅网络选项卡(chrome)并查看请求url。可以添加更多信息