Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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 检查数据库中是否存在代码_Php_Jquery_Mysql_Ajax_Mysqli - Fatal编程技术网

Php 检查数据库中是否存在代码

Php 检查数据库中是否存在代码,php,jquery,mysql,ajax,mysqli,Php,Jquery,Mysql,Ajax,Mysqli,我想问我的代码出了什么问题。我想制作一个网站,在其中输入代码,ajax发送请求php文件,然后mysqli查询检查数据库中是否存在代码并返回结果。这是我的Php文件、ajax reguest和html输入代码 数据库一切正常,因为我有一个名为“user”的表,还有一个名为“testas”的koda,所以这不是那种错误 每次php文件返回到ajax“0”,因为我从console.log看到它 PHP HTML 查看开发人员控制台,使用php的错误报告并检查查询中的错误。对不起,我是新手,我该怎么

我想问我的代码出了什么问题。我想制作一个网站,在其中输入代码,ajax发送请求php文件,然后mysqli查询检查数据库中是否存在代码并返回结果。这是我的Php文件、ajax reguest和html输入代码

数据库一切正常,因为我有一个名为“user”的表,还有一个名为“testas”的koda,所以这不是那种错误

每次php文件返回到ajax“0”,因为我从console.log看到它

PHP

HTML



查看开发人员控制台,使用php的错误报告并检查查询中的错误。对不起,我是新手,我该怎么做?
issusta
!==<代码>输入文本…很难说HTML是什么样子。编辑:哦,那是刚刚添加的,至少是“一些”。你应该使用
$kodas=$\u POST[“issiusta”],正如@jeroen所指出的。
<?php
    $mysqli = new mysqli('localhost' , 'username', 'password', 'database');
    if ($mysqli->connect_error){
        echo 2;
    }

    $kodas = $_POST["input-text"];

    $statement = $mysqli->prepare("SELECT kodas FROM user WHERE kodas = ?");
    $statement->bind_param('s', $kodas);
    $statement->execute();
    $statement->bind_result($kodas);
    if($statement->fetch()){
        echo 1;
    }else{
        echo 0;
    }

?>
jQuery(document).ready(function() {
    jQuery('#input-button').on('click', function(){
       var kodas = document.getElementById("input-text").value;
       jQuery.ajax({                
           url: "link to file.php", 
           type: 'POST',
           data : { issiusta: kodas },  
           success: function(array) {
            console.log(array);
            if(array == 1){
                  alert("Code exist!");
            }else if(array ==2) {
                  alert("Can't Connect to Database");
            } else {
                  alert("Error");
            }
           }
       }); 
    }); 
}); 
<input id="input-text" name="input-text" type="text" value="Slaptas Kodas" onblur="if (this.value == '') {this.value = 'Slaptas Kodas';}"onfocus="if (this.value == 'Slaptas Kodas') {this.value = '';}"/>
  <input id="input-button" type="submit" value="Prisijungti" />