Jump to content

Submit refusing to submit


CoffeeAddict

Recommended Posts

I have a list of requests to purchase a "dog" on my site. The list shows up fine, but when I hit submit or reject, it just redirects to the same page and nothing happens, This was previously working fine and now for whatever reason I can't seem to spot the problem. Help please?

 

This is earlier in the page:

 

if ($_POST['accept_buy_request']) {
    $user->acceptRequestBuy($_POST['request_id']);
}

if ($_POST['reject_buy_request']) {
    $user->rejectRequestBuy($_POST['request_id']);
}
 

Further down same page:

 

<table class="table table-striped">
    <tr>
        <td>Requester</td>
        <td>Amount</td>
        <td></td>
    </tr>';

    // Get all requests
    $result = mysql_query("SELECT
                                RB.id,
                                RB.user_id,
                                RB.amount,
                                U.display_name
                           FROM requests_buy RB
                           INNER JOIN users U ON U.id = RB.user_id
                           WHERE RB.dog_id = '$dog->id'
                           ORDER BY
                                   RB.created ASC,
                                   RB.amount DESC,
                                   RB.user_id ASC")
        or die('Cannot get buy requests: ' . mysql_error());

    while ($row = mysql_fetch_assoc($result)) {
        echo '
    <tr>
        <td><a href="kennel.php?id=', $row['user_id'], '">', $row['display_name'], '</a> (#', $row['user_id'], ')</td>
        <td>$', number_format($row['amount'], '2'), '</td>
        <td>
            <form action="dog.php?id=', $dog->id, '&requests=buy" method="post">
                <input type="hidden" name="request_id" value="', $row['id'], '" />
                <input type="submit" name="accept_buy_request" value="Accept" />
                <input type="submit" name="reject_buy_request" value="Reject" />
            </form>
        </td>
    </tr>';
    }

    if (!mysql_num_rows($result)) {
        echo '
    <tr>
        <td colspan="3">No requests to purchase have been made.</td>
    </tr>';
    }

    echo '
</table>

 

This is in the oop

 

public function acceptRequestBuy($request_id) {
        if (!$request_id || !is_numeric($request_id) || $request_id < 1) {
            echo 'Invalid request.';
            return;
        }

        $request_id = (int)$request_id;

        $result = mysql_query("SELECT
                                    RB.id,
                                    RB.user_id,
                                    RB.dog_id,
                                    RB.amount
                               FROM requests_buy RB
                               INNER JOIN dogs D ON D.id = RB.dog_id
                               WHERE
                                       RB.id = '$request_id' AND
                                       D.owner = '$this->id'
                               LIMIT 1")
            or die('Cannot check of legitimate request: ' . mysql_error());

        $row = mysql_fetch_assoc($result);

        if (!$row['id']) {
            echo 'That request does not exist.';
            return;
        }

        // Check if the requester can afford the request
        $requester = new User($row['user_id']);

        if (!$requester->id) {
            echo 'That user does not exist.';
            return;
        }
        
        if(!$requester->kennelSpaceAvailable){
            echo "<div class='alert alert-error'><b>No Kennel Space Available</b><br>The requester doesn't have enough kennel space.</div>";
            return;
        }

        if ($requester->money - $row['amount'] < 0) {
            echo 'That user cannot afford to purchase the dog for that amount.';
            return;
        }

        // Accept the request
        mysql_query("UPDATE dogs
                     SET
                             owner = '$requester->id}',
                             sell = 0,
                             autosell = 0
                     WHERE id = '{$row['dog_id']}'
                     LIMIT 1")
            or die('Cannot update dog: ' . mysql_error());

        mysql_query("UPDATE users
                     SET money = money - '{$row['amount']}'
                     WHERE id = '$requester->id}'
                     LIMIT 1")
            or die('Cannot update buyers money: ' . mysql_error());

        mysql_query("INSERT INTO users_transactions (id, date, type, description)
                     VALUES (
                                 '$requester->id}',
                                 '" . date("Y-m-d H:i:s") . "',
                                 'Dog',
                                 '- $" . number_format($row['amount'], 2, '.', '') . " for a dog.'
                             )")
            or die('Cannot create buyer transaction: ' . mysql_error());

        mysql_query("UPDATE users
                     SET money = money + '{$row['amount']}'
                     WHERE id = '$this->owner'
                     LIMIT 1")
            or die('Cannot update sellers money: ' . mysql_error());

        mysql_query("INSERT INTO users_transactions (id, date, type, description)
                     VALUES (
                                 '$this->owner',
                                 '" . date("Y-m-d H:i:s") . "',
                                 'Dog',
                                 '+ $" . number_format($row['amount'], 2, '.', '') . " for a dog.'
                             )")
            or die('Cannot create seller transaction: ' . mysql_error());

        // Remove requests to buy
        mysql_query("DELETE FROM requests_buy
                     WHERE dog_id = '{$row['dog_id']}'")
            or die('Cannot remove buy requests: ' . mysql_error());

        if ($dog->pregnant) {
            mysql_query("UPDATE litters
                         SET owner = '$requester->id
                         WHERE dam = '{$row['dog_id']}'")
                or die('Cannot update litter(s): ' . mysql_error());

        }

        $this->money += $row['amount'];

        unset($_POST);

        echo 'Successfully accepted a request to purchase this dog.';
        return;
    }

    public function rejectRequestBuy($request_id) {
        if (!$request_id || !is_numeric($request_id) || $request_id < 1) {
            echo 'Invalid request.';
            return;
        }

        $request_id = (int)$request_id;

        $result = mysql_query("SELECT RB.id
                               FROM requests_buy RB
                               INNER JOIN dogs D ON D.id = RB.dog_id
                               WHERE
                                       RB.id = '$request_id' AND
                                       D.owner = '$this->id'
                               LIMIT 1")
            or die('Cannot check of legitimate request: ' . mysql_error());

        $row = mysql_fetch_assoc($result);

        if (!$row['id']) {
            echo 'That request does not exist.';
            return;
        }

        // Remove request to buy
        mysql_query("DELETE FROM requests_buy
                     WHERE id = '{$row['id']}'")
            or die('Cannot remove buy request: ' . mysql_error());

        unset($_POST);

        echo 'Successfully rejected a request to purchase this dog.';
        return;
    }
 

 

Link to comment
Share on other sites

what steps have you taken to debug what your code and data are doing on your server to pin down exactly at what point in the code they aren't doing what you expect? i.e we don't have the ability to run your code with your data, nor do we have all your relevant code to even attempt to reproduce the problem.

 

also, Please use the forum's


bbcode tags (the edit form's <> button) when posting code.

Edited by mac_gyver
Link to comment
Share on other sites

Thank you for the response. I did some googling to figure out how to find the errors and these are the ones I'm getting:

Notice: Undefined index: accept_buy_request in /home/bestinsh/public_html/dog.php on line 43

Notice: Undefined index: reject_buy_request in /home/bestinsh/public_html/dog.php on line 47

 

I did additional googling and apparently I'm supposed to use isset in front of POST, which I tried but didn't make any difference. If I understand correctly, no variables are getting passed when the submt button is clicked?

 

I didn't write this code myself, I'm trying to figure out how to fix it without bothering my coder this morning, so far I'm failing, haha

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.