Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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 msql中的insert语句失败_Javascript_Php_Mysql_Sql - Fatal编程技术网

Javascript msql中的insert语句失败

Javascript msql中的insert语句失败,javascript,php,mysql,sql,Javascript,Php,Mysql,Sql,以下是导致我出现问题的代码部分: $usertype = $_POST['usertype']; if ($usertype == "Administration") { ?> <script type='text/javascript'> window.onload = promptMessage; function promptMessage() { var x = 38773; var code = prompt('Enter the admin

以下是导致我出现问题的代码部分:

$usertype = $_POST['usertype'];
if ($usertype == "Administration") {

?>

<script type='text/javascript'>
window.onload = promptMessage;

function promptMessage() {

    var x = 38773;

    var code = prompt('Enter the administration code you have been given:', 'Enter code here');

    if (code == x) {
        alert("Administration code accepted");

    } else {
        var secondcode = prompt('The code you have entered is inccorect', 'Enter correct code here or change Usertype');
        if (secondcode == x) {
            alert("Administration code accepted");
        } else {
            location.href = 'AdminCodeFail.html';
        }
    }
}  
</script>
<?php
$con = mysqli_connect("localhost:3306", "root", "***********", "systemone");

$sql = "INSERT INTO completeinfo (FirstName, Surname, UniID, 
                                       HouseNumber, AddressLineOne, AddressLineTwo, City, 
                                       PostCode, County, PhoneNumber, Email, Username, 
                                       Password, UserType)
                                       VALUES
                                       ('$_POST[firstname]','$_POST[surname]','$_POST[uniid]',
                                       '$_POST[housenumber]','$_POST[addresslineone]',
                                       '$_POST[addresslinetwo]','$_POST[city]','$_POST[postcode]',
                                       '$_POST[county]','$_POST[contactnumber]','$_POST[email]',
                                       '$_POST[username]','$_POST[password]','$_POST[usertype]')";

if (!mysqli_query($con, $sql)) {
    die('Error: ' . mysqli_error($con));
} else {
    header("Location:SignUpComplete.html");
}
$usertype=$\u POST['usertype'];
如果($usertype==“管理”){
?>
window.onload=promptMessage;
函数promptMessage(){
var x=38773;
var code=prompt('输入您收到的管理代码:','在此处输入代码');
如果(代码==x){
警报(“接受管理代码”);
}否则{
var secondcode=prompt('您输入的代码是inccorect','在此处输入正确的代码或更改用户类型');
if(secondcode==x){
警报(“接受管理代码”);
}否则{
location.href='AdminCodeFail.html';
}
}
}  
加

在您的代码之后,它将为您提供更多关于查询失败原因的描述性错误

  • 不能将数组变量用双引号括起来,如下所示:

    $string = "hello $array['index'] world!";
    
    它们必须是:

    $string = "hello {$array['index']} world!";
    
  • 您的代码在wazoo上存在SQL注入漏洞。我强烈建议阅读:

  • 这是您的错误,此类问题已得到回答

    使用

    .mysql\u real\u escape\u string
    从字符串中弹出并识别值


    查看链接…它会有帮助:)

    也许事务没有提交?echo$sql;并在mysql中复制相同的查询,看看你得到了什么!!两件事…首先,我认为你需要使一个变量等于你的$_POST['firstname'],然后将该变量传递到你的mysql select中(我不是php专家,但这就是我所做的,它可以工作)。其次,在phpsession_start();include('/include/connection.php');$user=$\u POST['user'];$pass=$\u POST['pass'];$query=“从FB_用户中选择密码,其中username='user'”;$sql\u pass=mysql\u query($query)$results=mysql\u fetch\u row($sql\u pass)…..请告诉我您是否真的应该切换到准备好的语句;变量中的
    '
    字符将破坏您的查询或更糟。另外请注意,您的查询仅在
    $\u POST['usertype]=“管理”时运行
    。无论您是直接使用$\u POST变量还是将其放入另一个变量,都应该对其进行转义(使用mysql\u real\u escaape\u string或类似工具)。如果你把它放在一个变量中,或者我应该说功能是用一个变量来处理的,那么就不会有错误。我不是编程专家或者其他任何人,所以我的做法会更好。但是要使用$\u POST literal值,你必须像我发布的链接一样转义。不,你没有。在w中使用$\u POST变量是完全合法的运算已经完成(即,将其用作普通数组,只是在下标周围没有引号),只是它对SQL注入非常开放。将它移动到一个变量并不能改变这个问题,因为它仍然对SQL注入非常开放,它只是为您提供了一条使用mysql\u real\u escape\u string的方便路线。我明白您的意思,也许使用单词have to不是最好的选择。但我是说最好使用它mysql\u real\u escape\u string…你在我发布的链接中读到Alix Axel给出的答案了吗?是的,但我的观点是,这不是一种非此即彼的情况。你是将字段直接放入SQL还是先将其移动到变量,与你是否需要将其转义以防止SQL注入无关。
    $query=“从FB_用户处选择密码,其中用户名='$User'”;
    对SQL注入是完全开放的,就像
    $query=“从FB_用户处选择密码,其中用户名='$\u POST[User]”;
    是完全开放的,并且两者在语法方面都同样有效。
    $string = "hello {$array['index']} world!";