dongque1462 2014-03-10 17:01
浏览 51
已采纳

在sql中失败的insert语句

Below is the section of my code which is causing me problems:

$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");
}

The problem I'm having is that the insert query is just not working. The query fails to insert any data into the database and I am at a loss as to why. The connection to the database is working fine and I'm receiving no errors when testing the query itself. So why isn't the query functioning?

  • 写回答

3条回答 默认 最新

  • douchen2595 2014-03-10 17:11
    关注

    Add

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    after your code and it will give you more descriptive errors as to why the query is failing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图