0

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

}

?>
4

1 に答える 1

1

おかしなことに、あなたの状態をチェックしてください

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

あなたのコードはうまく機能していると思います。:)

于 2012-09-05T13:01:52.403 に答える