0

I want my db table to update when the button hire is clicked i can't find the problem. I receive no errors but my table wont update I hope someone can please go over my scripts below and be able to point out my mistakes.

This is my hire_staff.php file

<?php
session_start();
include("header.php");
?>
<?php
$chief_aerodynamicist = $staff['chief_aerodynamicist'];
$chief_designer = $staff['chief_designer'];
$commercial_director = $staff['commercial_director'];
$pit_crew = $staff['pit_crew'];
$technical_director = $staff['technical_director'];




?>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">


    $(document).ready(function(){
        $(".button").click(function(e){
            $.ajax({
                url: "hire.fire.php",
                type: "POST",
                data: {colID: e.target.id},
                success: function(data){
                    data = JSON.parse(data);

                }
            });
        });
    });

</script>
</head>

<center><h2>You can hire new staff here</h2></center>

<table cellpadding="3" cellspacing="5">
        <tr>
            <td>Chief Aerodynamicist:</td>
            <td><i><?php echo "Level $chief_aerodynamicist"; ?></i></td>
            <td><form><input type="button" class="button" id="chief_aerodynamicist" value="Hire!"/></form></td>
        </tr>
          <tr>   
            <td>Chief Designer:</td>
            <td><i><?php echo "Level $chief_designer"; ?></i></td>
            <td><form><input type="button" class="button" id="chief_designer" value="Hire!"/></form></td>
        </tr>
          <tr>               
            <td>Commercial Director:</td>
            <td><i><?php echo "Level $commercial_director"; ?></i></td>
            <td><form><input type="button" class="button" id="commercial_director" value="Hire!"/></form></td>
        </tr>
          <tr>  
            <td>Pit Crew:</td>
            <td><i><?php echo "Level $pit_crew"; ?></i></td>
            <td><form><input type="button" class="button" id="pit_crew" value="Hire!"/></form></td>
        </tr>
        <tr>  
            <td>Technical Director:</td>
            <td><i><?php echo "Level $technical_director"; ?></i></td>
            <td><form><input type="button" class="button" id="technical_director" value="Hire!"/></form></td>
        </tr>


</table>



<?php
echo "$colID";
include("footer.php");
?>

and my hire.fire.php

<?php
include("functions.php");
connect();
if(isset($_POST['colID'])){
    $colID = mysql_real_escape($_POST['colID']); 
    $userID = mysql_real_escape($_SESSION['uid']);
    mysql_query("UPDATE  `staff` SET  `$colID` =  '6' WHERE `id`='$userID'") or die(mysql_error());


   $query = mysql_query("SELECT FROM `staff` WHERE `id`='$userID'")or die(mysql_error());
    $results = mysql_fetch_assoc($query);
    echo json_encode($results);
}
?>
Pete
  • 57,112
  • 28
  • 117
  • 166
evin
  • 125
  • 1
  • 2
  • 8

1 Answers1

0

I don't know if this helps but once I had a similar query with the same problem. I just took out the backticks (``) and it worked. I would try using:

UPDATE staff SET $colID = '6' WHERE id = '$userID'

instead of

UPDATE `staff` SET `$colID` = '6' WHERE `id` = '$userID'
pwc
  • 7,043
  • 3
  • 29
  • 32
LBBO
  • 85
  • 1
  • 9