使用php自定义函数将值插入mysql

使用php自定义函数将值插入mysql,php,Php,我想在MySQL数据库中插入值,但这些值没有插入,我不知道出了什么问题 这是我的密码: <?php include("inc/connection.php"); function RegisterStep1() { $txtuser = $_POST['txtName']; $txtsurname = $_POST['txtSurname']; $txtemail = $_POST['txtEmail']; $txtp

我想在MySQL数据库中插入值,但这些值没有插入,我不知道出了什么问题

这是我的密码:

<?php


include("inc/connection.php");

function RegisterStep1() {

        $txtuser = $_POST['txtName'];
        $txtsurname = $_POST['txtSurname'];
        $txtemail = $_POST['txtEmail'];
        $txtpass = $_POST['txtPassword'];
        $txtconfirmpass = $_POST['txtConfirmPass'];
        $txtcontactperson = $_POST['txtcompanycontactname'];
        $txtCompAddress = $_POST['txtCompAddress'];
        $txtRegNo = $_POST['txtRegNo'];
        $txtuserpos = $_POST['txtuserpos'];
        $txtdepartment = $_POST['txtdepartment'];
        $txtcontacts = $_POST['txtcontacts'];
        /* check if values are posted */



        $txtuser = mysql_real_escape_string($_POST['txtName']);
        /* combo company type */
        $txtCompAddress = mysql_real_escape_string($_POST['txtCompAddress']);
        /* combo locations
         */
        $txtRegNo = mysql_real_escape_string($_POST['txtRegNo']);
        /* combo companysize */
        $txtcontactperson = mysql_real_escape_string($_POST['txtcompanycontactname']);
        $txtsurname = mysql_real_escape_string($_POST['txtSurname']);
        $txtuserpos = mysql_real_escape_string($_POST['txtuserpos']);

        $txtdepartment = mysql_real_escape_string($_POST['txtdepartment']);
        $txtcontacts = mysql_real_escape_string($_POST['txtcontacts']);
        $txtemail = mysql_real_escape_string($_POST['txtEmail']);
        $txtpass = mysql_real_escape_string($_POST['txtPassword']);
        $txtconfirmpass = mysql_real_escape_string($_POST['txtConfirmPass']);



        $q = "INSERT INTO company(Name,Type,Address,Location,RegisteredNumber,CompanySize,ContactPerson,Surname,Position,Department,Contacts,DateResgistered,AccountStatus,Email,Password)
      Values('" . $txtuser . "','" . $txtCompAddress . "','" . $txtRegNo . "','" . $txtcontactperson . "','" . $txtsurname . "','" . $txtuserpos . "','" . $txtRegNo . "','" . $txtdepartment . "','" . $txtcontacts . "','" . $txtemail . "','" . $txtpass . "')";

        $submitquery = mysql_query($q);
        if ($submitquery) {
            echo"<div id='results'>Error occured while creating account,please try again in few minutes</div>";
        } else {
            echo "<div id='results'>Thanks for signing up</div>";
        }

}

?>

有件有趣的事,请检查一下你的情况

$submitquery = mysql_query($q);
        if ($submitquery) {
            echo"<div id='results'>Error occured while creating account,please try again in few minutes</div>";
        } else {
            echo "<div id='results'>Thanks for signing up</div>";
        }
$submitquery=mysql\u查询($q);
如果($submitquery){
echo“创建帐户时出错,请几分钟后重试”;
}否则{
echo“感谢注册”;
}
应该是

$submitquery = mysql_query($q);
            if (!$submitquery) {
                echo"<div id='results'>Error occured while creating account,please try again in few minutes</div>";
            } else {
                echo "<div id='results'>Thanks for signing up</div>";
            }
$submitquery=mysql\u查询($q);
如果(!$submitquery){
echo“创建帐户时出错,请几分钟后重试”;
}否则{
echo“感谢注册”;
}

我认为您的代码运行良好。:)

您得到的输出是什么?最后是否出现了错误?请使用
echo mysql\u Error()
找出您遇到的错误。发布更少的代码。将您的代码减少到仍然产生错误的最小样本,并发布剩下的内容。同时,你自己也可能会发现这个问题。这是调试,在要求堆栈溢出为您执行此操作之前,您需要自己尝试。输出是创建帐户时出错的,请在几分钟后重试。我一直在尝试跟踪它,但没有得到任何粘合。让我尝试mysql\u Error()以找出哪里出了问题。
mysql\u Error()的输出是什么
+1和deceze感谢mysql_error()问题出在查询本身,但我不知道如何调试它。它现在工作正常,谢谢:)。谢谢大家。如果遇到任何问题,我会再次发布