2017-03-21 49 views
-1

喜在那裏工作我已經嘗試了一切,但我不能得到這個工作,我嘗試從MySQL數據庫中的數據加載到窗體,然後當它已被編輯爲它保存了更新查詢PHP的MySQL更新查詢並不

這裏是我的代碼:

  <p>Trainer Name: </p> 
    <td><input type='text' name='TrainerName' value="<?php echo $Row['Trainer_name'] ?>"></td> 

     <p>Trainer Load URL: <sup>(This is where the trainer is located on the server make sure its in the resources folder)</sup> </p> 
     <td><input type='text' name='TrainerLoadUrl' value="<?php echo $Row['Trainer_url'] ?>"></td> 

     <p>Trainer Load Description: <sup>(This is the Txt file for the description)</sup></p> 
     <td><input type='text' name='TrainerLoadDescription' value="<?php echo $Row['Trainer_url_description'] ?>"></td> 

     <p>Trainer File Short Name: <sup>(This is the short name for the trainer so the program knows how to handle the request)</sup></p> 
     <td><input type='text' name='TrainerFileShortName' value="<?php echo $Row['Trainer_url_button_filename'] ?>"></td> 
     <a id="Save" href=""><button type="submit" name="btn-save" class="btn btn-primary pull-left"><i class="glyphicon glyphicon-save"></i> Save</button></a> 

     <?php 
     if(isset($_POST['btn-save'])) { 

      mysql_connect("localhost", "tsbannoo", "aces111") or die("Connection Failed"); 
      mysql_select_db("tsbannoo_vip")or die("Connection Failed"); 


      $TrainerID = $_GET['id']; 
      $TrainerName = $_POST['TrainerName']; 
      $TrainerLoadUrl = $_POST['TrainerLoadUrl']; 
      $TrainerLoadDescription = $_POST['TrainerLoadDescription']; 
      $TrainerFileShortName = $_POST['TrainerFileShortName']; 

      $query = mysql_query("UPDATE Trainers SET Trainer_name = '$TrainerName', Trainer_url = '$TrainerLoadUrl', Trainer_url_description = '$TrainerLoadDescription', Trainer_url_button_filename = '$TrainerFileShortName' WHERE trainer_id = '$TrainerID'"); 
      if(mysql_query($query)){ 
       echo "updated";} 
      else{ 
       echo "fail";} 





     } 
     ?> 
+1

'$查詢=請求mysql_query(.....如果(的mysql_query($查詢))'是在這裏失敗,'echo'失敗';'沒有幫助你。' –

+0

我該怎麼辦? –

+0

'if($ query){'就夠了 –

回答

0

添加打開和關閉標籤。將方法屬性設置爲「post」。

<form action="" method="post"> 
Rest of your HTML... 
</form> 

從您的按鈕取下錨標記封裝所以這...

<a id="Save" href=""><button type="submit" name="btn-save" class="btn btn-primary pull-left"><i class="glyphicon glyphicon-save"></i> Save</button></a> 

變爲這個...

<button type="submit" name="btn-save" class="btn btn-primary pull-left"><i class="glyphicon glyphicon-save"></i> Save</button> 

確保該按鈕的標籤是關閉標籤內。

而且,改變了...

$query = mysql_query("UPDATE Trainers SET Trainer_name = '$TrainerName', Trainer_url = '$TrainerLoadUrl', Trainer_url_description = '$TrainerLoadDescription', Trainer_url_button_filename = '$TrainerFileShortName' WHERE trainer_id = '$TrainerID'"); 

爲了這...

$query = "UPDATE Trainers SET Trainer_name = '$TrainerName', Trainer_url = '$TrainerLoadUrl', Trainer_url_description = '$TrainerLoadDescription', Trainer_url_button_filename = '$TrainerFileShortName' WHERE trainer_id = '$TrainerID'"; 
+0

不讓這個部分答案;覆蓋 –

+0

記住,這使他們打開SQL注入 –

+0

YAY一切!謝謝你這麼多的工作現在:) –