您好我已经尝试了一切,但我无法让这个工作我试图将数据从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";}
}
?>
答案 0 :(得分:0)
添加开始和结束标记。将method属性设置为“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'");
To This ...
$query = "UPDATE Trainers SET Trainer_name = '$TrainerName', Trainer_url = '$TrainerLoadUrl', Trainer_url_description = '$TrainerLoadDescription', Trainer_url_button_filename = '$TrainerFileShortName' WHERE trainer_id = '$TrainerID'";