2013-12-20 43 views
0

我必須爲學校做一個網站。它需要與數據庫鏈接。在localhost一切正常和作品,但是當我試圖把它上傳學校的主機上,我得到這個錯誤:未定義的索引PHP放置在主機上

Notice: Undefined index: vragen in /mnt/studentenhomes/arnaud.gandibleux/public_html/datamanagement/index.php on line 44

我無法找到解決辦法

的index.php

<div id="tekst"> 
      <table align='center'> 
       <?php 
       //if (isset($_GET['vragen'])){ 

       if ($_GET['vragen'] === 'Alleclubs') { 
        getclubs(); 

       } elseif ($_GET['vragen'] === 'ledenvjf') { 
        getVJFleden(); 
        echo "test"; 
       } elseif ($_GET['vragen'] === 'ledenffbj') { 
        getFFBJleden(); 
       } 

       elseif (isset($_GET['clubnr'])) { 
        getLedenPerClubEnID($_GET['clubnr']); 
       } 
       else{ 
        getclubs(); 
       } 
       // } 
       ?> 
      </table> 

Crud.php

 function getVJFleden() { 
     global $mysqli; 

     $result = $mysqli->query("SELECT * FROM Leden l JOIN Clubs c ON l.clubnr = c.clubnr join Bonden b 
    ON b.ID_bond = c.ID_bond LEFT JOIN adressen a ON a.ID_adress = l.ID_adress WHERE b.naam_bond = 'VJF';"); 
     if ($result) { 
      if ($result->num_rows > 0) { 
       echo"<caption>Alle leden VJF</caption>"; 
       echo "<th>Voornaam</th><th>achternaam</th><th>leeftijd</th><th>Kye</th><th>adress</th>"; 
       while ($leden = $result->fetch_object()) { 
        echo "<tr><td>$leden->lid_voornaam</td> "; 
        echo "<td>" . $leden->lid_achternaam . "</td> "; 
        echo "<td>" . $leden->lid_leeftijd . "</td> "; 
        echo "<td>" . $leden->kye . "</td> "; 
        echo "<td>" . $leden->straatnaam . " " . $leden->huisnummer . " " . $leden->postcode . " " . $leden->gemeente . "</td> "; 
        echo "<td><form id='update' action='update.php' method='POST'> 
         <input type='hidden' name='id' value='" . $leden->ID_lid . "'/> 
         <input type='hidden' name='clubnr' value='" . $_GET['clubnr'] . "'/> 
         <input type='image' src='update.png' alt='Update' width='22' height='22'> 
         </form> 
         <form id='delete' action='deleteLid.php' method='POST'> 
         <input type='hidden' name='id' value='" . $leden->ID_lid . "'/> 
         <input type='image' src='delete.png' alt='detele' width='22' height='22'> 
         </form></td> "; 
       } 
      } 
     } 
     $mysqli->close(); 
    } 

    function getFFBJleden() { 
     global $mysqli; 
     #, Adressen a 
     #AND l.ID_adress = a.ID_adress 
     $result = $mysqli->query("SELECT * FROM Leden l JOIN Clubs c ON l.clubnr = c.clubnr join Bonden b ON b.ID_bond = c.ID_bond LEFT JOIN adressen a ON a.ID_adress = l.ID_adress WHERE b.naam_bond = 'FFBJ';"); 
     if ($result) { 
      if ($result->num_rows > 0) { 
       echo"<caption>Alle leden VJF</caption>"; 
       echo "<th>Voornaam</th><th>achternaam</th><th>leeftijd</th><th>Kye</th><th>adress</th>"; 
       while ($leden = $result->fetch_object()) { 

        echo "<tr><td>$leden->lid_voornaam</td> "; 
        echo "<td>" . $leden->lid_achternaam . "</td> "; 
        echo "<td>" . $leden->lid_leeftijd . "</td> "; 
        echo "<td>" . $leden->kye . "</td> "; 
        echo "<td>" . $leden->straatnaam . " " . $leden->huisnummer . " " . $leden->postcode . " " . $leden->gemeente . "</td> "; 
        echo "<td><form id='update' action='update.php' method='POST'> 
         <input type='hidden' name='id' value='" . $leden->ID_lid . "'/> 
         <input type='hidden' name='clubnr' value='" . $_GET['clubnr'] . "'/> 
         <input type='image' src='update.png' alt='Update' width='22' height='22'> 
         </form> 
         <form id='delete' action='deleteLid.php' method='POST'> 
         <input type='hidden' name='id' value='" . $leden->ID_lid . "'/> 
         <input type='image' src='delete.png' alt='detele' width='22' height='22'> 
         </form></td> "; 
       } 
      } 
     } 
     $mysqli->close(); 
    } 
+9

您註釋掉一個行可以防止這個錯誤 –

+2

由於您正在訪問'$ _GET ['vragen']',並且'$ _GET'數組不包含關鍵字'vragen',因爲您沒有在URL中提供它。 – h2ooooooo

回答

1

您需要確保數組索引你之前存在嘗試使用它。因爲它是一個$_GET變量,所以它可能沒有作爲URL參數傳遞。

取消註釋

//if (isset($_GET['vragen'])){ 

if (isset($_GET['vragen'])){ 
+0

我試過它已與「isset()」..但他沒有提供任何..和本地主機我工作很好..:s – Upriser

0

兩件事情正在發生:

  1. 你有通知警告。請參閱此處瞭解如何關閉它們:(How do I turn off PHP Notices?)
  2. 它可能是您未在網址上指定的$ _GET參數之一。因此,當您加載頁面時,您正在訪問$ _GET超全局,但可能沒有任何內容,並且您試圖打印出該值。

您可以關閉通知或使用函數從$ _GET中獲取值,並在此函數中檢查值isset(),然後再訪問它。

+0

Thx的答案,但我沒有找到解決方案..可以是某事其他? – Upriser

+0

@冒犯者,你嘗試了什麼? – Jay

+0

設置警告關閉並取消推薦「isset()」 – Upriser

0

這意味着變量vragen未設置,因此您的$ _GET數組沒有任何索引爲vragen的元素。
取消註釋//if (isset($_GET['vragen'])){// },因爲這是檢查是否設置了名稱爲vragen的$ _GET變量。 mysite.com?vragen=ledenvjf 如果你忘了後的部分:當此檢查將通過index.php?vragen=ledenvjf

0

當你訪問你做的東西喜歡的網站
例子?沒有$_GET['vragen']並通知被拋出

此行

//if (isset($_GET['vragen'])){ 

防止通知被甩出,你應該用這條線一起取消其註釋:

// }