简体   繁体   English

我无法将数据插入数据库phpmyadmin

[英]I can't insert my data to database phpmyadmin

I got a problem in my code I try to insert my data to database phpmyadmin,when I click submit button the error message it not generating any errors...this is my code : 我在代码中遇到问题,我尝试将数据插入数据库phpmyadmin中,当我单击“提交”按钮时,错误消息未生成任何错误...这是我的代码:

file.php php file file.php php文件

<?php $cnx = mysql_connect("localhost", "root", "MUdp5HMPxExXKGGt");
if(!$cnx) 
    echo"Echec de la connexion !!!"; 
$cnx = new PDO("mysql:host=localhost;dbname=utilisateur","root","MUdp5HMPxExXKGGt");

if(isset($POST['valider'])){
    $nom=$POST['nom'];
    $prenom=$POST['prenom'];
    $date=$POST['date'];
    $sexe=$POST['sexe'];
    $adr=$POST['adr'];
    $formation=$POST['formation'];
    $email=$POST['email'];
    $tel=$POST['tel'];

    $req = "insert into utilisateurs values('".$nom."','".$prenom."','".$date."','".$sexe."','".$adr."','".$formation."','".$email."','".$tel."')";
    $sql=$cnx->exec($req);

    if($sql===FALSE){
        print_r($cnx->errorInfo());
        die();
    }else{
        echo "bien ajouter";
    }
}

if(isset($POST['valider'{
    $nom=$POST['nom'];
    $prenom=$POST['prenom'];
    $date=$POST['date'];
    $sexe=$POST['sexe'];
    $adr=$POST['adr'];
    $formation=$POST['formation'];
    $email=$POST['email'];
    $tel=$POST['tel'];
    $req = "insert into utilisateurs values('".$nom."','".$prenom."','".$date."','".$sexe."','".$adr."','".$formation."','".$email."','".$tel."')";
    $sql=$cnx->exec($req);

    if($sql===FALSE){ 
        print_r($cnx->errorInfo()); 
        die();
    } else {
        echo "bien ajouter";}
    }
}
?>

file.html fichier html file.html文件HTML

<html><head><title>premier tp</title></head><body><br><h2 align="center"><u>Formulaire d'inscription<u></h2><br>
    <table width="600" align="center" cellspacing=7 >
    <form action="Premier_tp.php" method="post" name="F">
        <tr><td><b>nom :<b></td>
            <td><input type="text" name="nom" size="40" style="background-color:#F09647"/></td>
            <td></td></tr>
            <tr><td><b>prenom :<b></td>
            <td><input type="text" name="prenom" size="40" style="background-color:#F09647"/></td>
            <td></td></tr>
            <tr><td><b>Date Naissance :<b></td>
            <td><input type="text" name="date" size="40" style="background-color:#F09647"/></td>
            <td></td></tr>
            <tr><td><b>Sexe :<b></td>
            <td><SELECT name="sexe"style="background-color:#F09647" >
                <OPTION value="femme">Femme</option><OPTION>value="homme">Homme</option></SELECT></td><td></td></tr><tr><td><b>Adresse :<b></td>
            <td><input type="text" name="Adr" size="40" style="background-color:#F09647"/></td>
            <td></td></tr>
            <tr ><td rowspan="3"><b>formation :<b></td>

            <td><input type="radio" name="formation" value="bac"/><b>BAC<b> </td></tr>
            <td></td>
            <tr>
            <td><input type="radio" name="formation" value="license"/><b>Lisence<b> </td></tr>
            <td></td>

            <td><input type="radio" name="formation" value="master"/><b>Master<b> </td></tr>
            <td></td></tr>

            <tr><td><b>Email:<b></td>
            <td><input type="text" name="email" size="40" style="background-color:#F09647"/></td>
            <td></td></tr>
            <tr><td><b>Telephone:<b></td>
            <td><input type="rext" name="tel" size="40" style="background-color:#F09647"/></td>
            <td></td></tr>
            <tr>
            <td colspan="2" align="center" ><input type="submit" name="valider" value="Valider" onsubmit="return verif()"  style="width:130px;height:40px;background-color:#F09647"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="submit" name="Annuler" value="Annuler" style="width:130px;height:40px;background-color:#F09647"/></td>
            <td></td></tr></form>
    </table>
    </body>
    </html>

You should be using 您应该使用

$_POST

and not $POST throughout your code. 而不是整个代码中的$ POST。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM