Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用post变量函数将Php插入mysql_Php_Mysql_Pdo - Fatal编程技术网

使用post变量函数将Php插入mysql

使用post变量函数将Php插入mysql,php,mysql,pdo,Php,Mysql,Pdo,我正在尝试使用以下函数在我的数据库中插入一些数据(我没有收到任何错误,但我的数据没有添加到我的数据库中)File name=insertuserdb: <?php function insertUser($U,$P,$E) { $conn = connPDO();//*function to connect to my DB on the other file $query = ("INSERT INTO user (Username, Password, Email) V

我正在尝试使用以下函数在我的数据库中插入一些数据(我没有收到任何错误,但我的数据没有添加到我的数据库中)File name=insertuserdb:

<?php
function insertUser($U,$P,$E)
{
    $conn = connPDO();//*function to connect to my DB on the other file
    $query = ("INSERT INTO user (Username, Password, Email) VALUES (:User,:Pass,:Email)");
    $conn_prepare = $conn->prepare($query);
    $conn_prepare->execute(array( "User" => $U,"Pass" => $P,"Email" =>$E ));
    $id = $conn->lastInsertId();
    $conn_prepare->closeCursor();
    return $id;
}

?>

和(我的连接函数(works/sorry for french))file name=dbc3.php:

<?php

function connPDO()
{
    $PARAM_hote='localhost'; // le chemin vers le serveur
    $PARAM_port='';
    $PARAM_nom_bd='mygcpage'; // le nom de votre base de données
    $PARAM_utilisateur='root'; // nom d'utilisateur pour se connecter
    $PARAM_mot_passe=''; // mot de passe de l'utilisateur pour se connecter
    try {
        $connexion = new PDO('mysql:host='.$PARAM_hote.';port='.$PARAM_port.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe);
        return $connexion;
    }
    catch(Exception $e) {
        echo 'Erreur : '.$e->getMessage().'<br />';
        echo 'N° : '.$e->getCode();
        die;
    }
}


$conn = connPDO();

if ($conn) {
    echo "connected";
} else {
    echo "ERROR: Could not connect!";
}

最后(我的表单)文件名=login.php:

<form method="POST" action="login.php">
                        <table id="reg">
                        <th>Please the fill in the following:</th>
                            <tr><!--Username -->
                                <td>
                                    <p>Username:</p>
                                </td>
                                <td>
                                    <input type="text" name="username" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p>Password:</p>
                                </td>
                                <td>
                                    <input type="password" name="pass1" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p>Comfirm Password:</p>
                                </td>
                                <td>
                                    <input type="password" name="pass2" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p>Email:</p>
                                </td>
                                <td>
                                    <input type="text" name="email" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="submit" name="register" />
                                </td>
                                <td></td>
                            </tr>
                        </table>
                    </form>

请填写以下内容:
用户名:

密码:

公司密码:

电邮:


希望你们能帮助我

根据您发布的代码,您似乎从未从表单中捕获任何数据。 当您提交表单时,它将重新加载login.php,并且对刚刚提交的数据不做任何处理。要访问此数据,请在login.php中使用


一旦获取了$\u POST数据,就可以运行insertUser函数。

有两件事。您的php文件名是inserdb,您在其中编写insert代码,但在表单操作中它是login.php?是什么?在insertdb页面中,没有将POST数据分配给任何变量?这不会影响。