-1

Hi there i have tried everything but i cant get this to work im trying to load data from the mysql database to the form then when it has been edited for it to be saved with a update query

here is my Code:

         <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";}





        }
        ?>
Kyle B
  • 3
  • 1

1 Answers1

0

Add an opening and closing tag. Set the method attribute to "post".

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

Remove the anchor tag wrapper from your button so this...

<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>

Becomes this...

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

Ensure the button tag is inside the closing tag.

Also, change this...

$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'";
Simon K
  • 1,503
  • 1
  • 8
  • 10