Updating information in the database using php

I am new to programming and I am trying to update a specific column in a database using php and javascript.

The database contains only 2 columns, seating and status. Basically I want the status to reset back to 1 if the status is currently 0. Can anyone point me in the right direction?

I have a class inside a div in my HTML:

<a class='two' href="javascript:databaseReset() ">Reset</a>

      

My javascript function (Part im struggling with):

    function databaseReset();
    $.ajax({
        url: "dbreset.php",
        type: "POST",
        data: {
            'seatnum': seatnum,
            'status': '1'
        },
        success: function () {
            alert("ok");
        }

function over(id) {
    selectedseat=$(id).attr('title');
    $(id).attr('src','images/mine.gif');
    $(id).attr('title', 'Available');
}

function out(id) {
    $(id).attr('src','images/available.gif');
}

      

my php file:

<?php
include("dbconnect.php");

$query="UPDATE seats SET status=1 WHERE status=0";

$link = mysql_query($query);
if (!$link) {
 die('error 2');
}


?>

      

+3


source to share


1 answer


I guess it was just a typo, but your function call should wrap parentheses around the ajax call:

function databaseReset(){   //<---*****Add these braces*****
  $.ajax({
    url: "dbreset.php",
    type: "POST",
    data: {
      'seatnum': seatnum,
      'status': '1'
    },
    success: function () {
        alert("ok");
  }
};  //<---*****Add these braces*******

      

your code seems to be declaring a function, but not assigning its functionality



In addition, the data section is unnecessary since it is not used. In fact, since you are not sending data, you can use the "GET" method instead.

Besides the fact that your code looks good, can you point out what the problem is?

0


source







All Articles