2012-10-14 44 views
0

我有一个在第22行PHP:错误变量未定义

\瓦帕\ WWW \ cible_envoi.php: “注意:未定义变量” 错误,我不能解决:

说明:未定义变量:喃用C

你能看看下面的代码,并解释我有什么问题吗?谢谢!

cible_envoi.php:

<?php 
try 
{ 
    $bdd = new PDO('mysql:host=localhost;dbname=chansonniersduquebec.com', 'root', ''); 
} 
catch (Exception $e) 
{ 
    die('Erreur : ' . $e->getMessage()); 
} 

$req = $bdd->prepare('INSERT INTO chansonniersduquebec.com (Nom) VALUES(?)'); 
$req->execute(array($_POST['Nom'])); // *** Line 22 *** 

Incription.html:

<form id="Formulaire" name="Formulaire" method="post" action="cible_envoi.php"> 
    <label> 
    <div align="center">Nom (votre nom d'artiste de préférence!) 
     <span class="style1">*</span> 
     <input type="text" name="Nom" id="Nom"/> 
    </div> 
    <p>&nbsp;</p> 
    <label> 
    ... 
    <input type="submit" name="Soumettre" id="Soumettre" value="Soumettre" /> 
</form> 
+3

如果您可以声明整个完整的错误消息,那么它会很好,因为它应该包含文件名和发现错误的行。 – Sven

+0

确切的错误信息是什么? @ user1115535 – marknatividad

+0

[PHP:“Notice:Undefined variable”和“Notice:Undefined index”]的可能重复(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-索引) – hakre

回答

1

$ BDD超出范围。

 <?php 
//Try this 

    try 
    { 
     $bdd = new PDO('mysql:host=localhost;dbname=chansonniersduquebec.com', 'root', ''); 

     // Insertion du message à l'aide d'une requête préparée 
      $req = $bdd->prepare('INSERT INTO chansonniersduquebec.com (Nom) VALUES(?)'); 

      $req->bindParam(1, $nom); 

      $nom = $_POST['Nom']; 

      $req->execute(); 
     } 
     catch (Exception $e) 
     { 
     die('Erreur : ' . $e->getMessage()); 
     } 



    ?> 

<?php 
//Try this 
     $bdd = null; 
    try 
    { 
     $bdd = new PDO('mysql:host=localhost;dbname=chansonniersduquebec.com', 'root', ''); 

     } 
     catch (Exception $e) 
     { 
     die('Erreur : ' . $e->getMessage()); 
     } 



     // Insertion du message à l'aide d'une requête préparée 
      $req = $bdd->prepare('INSERT INTO chansonniersduquebec.com (Nom) VALUES(?)'); 

      $req->bindParam(1, $nom); 

      $nom = $_POST['Nom']; 

      $req->execute(); 


    ?> 

请,也使您的输入姓名和身份证一个字(样式joués)。

+0

谢谢,第二个代码有助于避免错误,但是我的变量不在我的数据库中呢? – user1115535

+0

我编辑过它。但要确保你的表名和列表匹配。 – Nwafor