2012-05-18 45 views
-2

我的問題是這樣的: 我的主頁有從數據庫中拉出行的表(while循環) 每行都有一個 - cell可以在其中添加一個事件爲了排 這樣做,我送行ID從主頁表 一個$ _GET變量,然後在「添加事件」頁面我把它保存爲一個變量 但是當我提出我的addEvent形式不正確加油吧(因爲我編碼)它只刷新窗體只有在沒有行ID的url爲此我也做的查詢頁拉開行數據不能再執行,並彈出一個PHP錯誤 的ID變量我簽署$ _GET和查詢(mysql fetch數組)。 當然,我從該查詢中顯示的所有數據都沒有了。

有關如何解決此問題的任何建議?在此先感謝,問候。

編輯:**殺死新人! - 對不起我猜

首頁在哪裏發送ID:

$sql = "SELECT * FROM alarms WHERE alarmstatus = 'OFF' and starttime='::' ORDER BY clientid ASC"; 
$query = mysql_query($sql); 
echo "<table cellpadding='1px' border='1px' bordercolor='#0066FF' cellspacing='0'> 
     <form action='hpage.php' method='get'>"; 
while($fetch = mysql_fetch_array($query)) { 
echo "<tr> 
      <td> 
      ".$fetch['clientid']."</td> 
      <td>".$fetch['controller']."</td> 
      <td>".$fetch['typeid']."</td> 
      <td style='color: red'>".$fetch['alarmstatus']."</td> 
      <td>".$fetch['starttime']."</td> 
      <td>".$fetch['endtime']."</td> 
      <td><a href='includes/editalarm.php?id=".$fetch['id']."'>Edit</a></td> 
      <td><a href='includes/addevent.php?id=".$fetch['id']."'>Add event</a></td> 
      <td><a href='includes/deletealarm.php?id=".$fetch['id']."'>Delete</a></td> 
    </tr>"; 
} 

添加事件從哪裏獲得的變量,並查詢:

$alarmid = $_GET['id']; 
    $sql = "SELECT * FROM alarms WHERE id=".$alarmid; 
    $query = mysql_query($sql); 
    $fetch = mysql_fetch_array($query); 
?> 

形式:

<table cellpadding="2px" cellspacing="0" > 
<form action="addevent.php" method="post"> 
    <tr> 
    <td>סניף:</td> 
    <td><input style="width:200px; background-color: #d6d6d6;" readonly name="client" value="<?php echo $fetch['clientid']; ?>" /></td> 
    </tr> 
    <tr> 
    <td>בקר:</td> 
    <td><input style="width:200px; background-color: #d6d6d6;" readonly name="controller" value="<?php echo $fetch['controller']; ?>" /></td> 
    </tr> 
    <tr> 
    <td>אזעקה:</td> 
    <td><input style="width:200px; background-color: #d6d6d6;" readonly name="controller" value="<?php echo $fetch['typeid']; ?>" /></td> 
    </tr> 
    <tr> 
    <td>מוקדן:</td> 
    <td> 
     <?php 
     $sql = "SELECT * FROM users WHERE privilege = '2'"; 
     $query = mysql_query($sql); 
     echo "<select name='user' style='width:207px;'>"; 
     echo "<option>..</option>"; 
     while ($fetch2 = mysql_fetch_array($query)){ 
     echo "<option>".$fetch2['username']."</option>"; 
     } 
     echo "</select>"; 
     ?>  
    </td> 
    </tr> 
    <tr> 
    <td>איש קשר:</td> 
    <td><input type="text" name="contact" /></td> 

    </tr> 
    <tr> 
    <td>הודעה:</td> 
    <td><input type="text" style="width:200px; height:100px" name="message" /></td> 
    </tr> 
    <tr> 
    <td>תשובה:</td> 
    <td><input type="text" style="width:200px; height:100px" name="answer" /></td> 
    </tr> 
    <tr> 
    <td>שעה:</td> 
    <td> 
     <select name="eventhour"> 
     <option value ="default"></option>   
     <?php 
      for($i = 0; $i<60; $i++){ 
      $value = $i; 
      if($i<=9){ 
       $value= "0".$i; 
      } 
      echo "<option>".$value."</option>"; 
      } 
     ?> 
     </select> 
     <select name="eventminute"> 
     <option value ="default"></option> 
     <?php 
      for($i = 0; $i<24; $i++){ 
      $value = $i; 
      if($i<=9){ 
       $value= "0".$i; 
      } 
      echo "<option>".$value."</option>"; 
      } 
     ?> 
     </select>   
    </td> 
    </tr> 
    <tr> 
    <td> 
     <input type="submit" name="save" value="שמור" /> 
     <input type="submit" name="cancell" value="בטל" /> 
    </td> 
    <td></td> 
    </tr> 
</form> 
+1

你能製作一些代碼嗎?並請發佈確切的錯誤 – Bono

+3

-1不提供代碼。理解代碼要比閱讀你寫的整個段落要容易得多。 –

+0

當您構建表單時,將get參數添加到action中,例如'action =「script.php?id = $ _ GET ['id']」',或者使用帶有id的隱藏表單元素,除非您在說話關於別的事。 –

回答

0

您的表單操作是POST。如果您將其更改爲GET,則您將具有$ _GET形式。