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条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能