doushouj966020 2016-03-14 16:23
浏览 70
已采纳

MySQL将值插入错误的列

Problem

With a php website, I have a form to collect information which will then be inserted into the MySQL database, but there are these three columns that have the wrong values inserted into them. The rest are all in the correct order.

Values inserted as php variables via MySQL transaction.

Thank you for your time.

phpmyadmin display (first row is manually corrected)

Code:

 <?php
function registerPatient($ptUsername, $ptPassword, $ptFirstName, $ptLastName, $ptSalutation, $ptEmail, $ptDOB, $ptPostCode, $ptHouseNo, $ptTelNo, $link)
{
    $accType = "Patient";
    $dtID = $_COOKIE["ID"];
    $errors = "";
    $SQL_patientInsert =

        "START TRANSACTION;

        INSERT INTO accDetails (`username`, `hashPassword`, `accType`)
        VALUES ('" . $ptUsername . "',
                '" . $ptPassword . "',
                '" . $accType . "');


        INSERT INTO ptProfile (`firstName`, `lastName`, `salutation`, `email`, `DOB`, `postCode`, `houseNo`, `telephoneNo`, `dtID`, `ptID`)
        VALUES ('" . $ptFirstName . "',
                '" . $ptLastName . "',
                '" . $ptSalutation . "',
                '" . $ptEmail . "',
                '" . $ptDOB . "',
                '" . $ptPostCode . "',
                '" . $ptHouseNo . "',
                '" . $ptTelNo . "',
                '" . $dtID . "',
                LAST_INSERT_ID());
        COMMIT;";

        if (mysqli_multi_query($link, $SQL_patientInsert)) {
            $errors .= "";
        } else {
            $errors .= "MYSQL Error: ". mysqli_error($link);
        }


        return $errors;

    }

?>

Var_Dump of $SQL_patientInsert

string(495) "START TRANSACTION; INSERT INTO accDetails (`username`, `hashPassword`, `accType`) VALUES ('bingbong', '$2y$10$WDvSHSxzIxaYB8dPGLRIWOFyIdPXxSw5JDXagOxeYuJUtnvFhI.lO', 'Patient'); INSERT INTO ptProfile (`firstName`, `lastName`, `salutation`, `email`, `DOB`, `postCode`, `houseNo`, `telephoneNo`, `dtID`, `ptID`) VALUES ('Dr', 'Bing', 'Bong', 'EMAIL REMOVED FOR SO', '1996-08-02', 'POSTCODE REMOVED FOR SO', '7', '83824', '1256', LAST_INSERT_ID()); COMMIT;"

Table Structure

Table Structure in PHPMyAdmin, no autoincrements, all values allowed to be null

  • 写回答

2条回答 默认 最新

  • dsvcqvp139098 2016-03-14 17:24
    关注

    Your are calling your function with wrong parameters order.

    Change this line ($ptFirstName <-> $ptSalutation);

    function registerPatient($ptUsername, $ptPassword, $ptFirstName, $ptLastName, $ptSalutation, $ptEmail, $ptDOB, $ptPostCode, $ptHouseNo, $ptTelNo, $link)
    

    with

    function registerPatient($ptUsername, $ptPassword, $ptSalutation, $ptFirstName, $ptLastName, $ptEmail, $ptDOB, $ptPostCode, $ptHouseNo, $ptTelNo, $link)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构