2012-10-14 77 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