-2

i want to delete the record in mysql database by just clicking on a link but i am unable to accomplish it, i am unable to understand the error. Here is my code

HTML

<a href="processCategory.php?action=delete?id=(<?php echo $id; ?>);">Delete</a>

processCategory.php

    <?php
    require_once '../library/config.php';
    require_once '../library/functions.php';

    checkUser();

    $action = isset($_GET['action']) ? $_GET['action'] : '';
    switch ($action) {

        case 'add' :
            addCategory();
            break;


        case 'delete' :
            deleteCategory();
            break;


        default :
            // if action is not defined or unknown
            // move to main category page
            header('Location: index.php');
    }


 function deleteCategory()
    {
        if (isset($_GET['id']) && (int)$_GET['id'] > 0) {
            $id = (int)$_GET['id'];
        } else {
            header('Location: index.php');
        }

        // delete the products
        $sql = "DELETE FROM tbl_vendors
                WHERE id = $id";
        dbQuery($sql);

        header('Location: ../vendor');
    }


    ?>
vamshi
  • 3
  • 4

2 Answers2

1

replace ? with & and remove "(" ")" and ; in your URL

<a href="processCategory.php?action=delete?id=(<?php echo $id; ?>);">Delete</a>

Your script processCategory.php Receives in the variable id this = (1) for example your out

echo (int) "(1)";

output

0

The correct code for the <a> tag should be as

<a href="processCategory.php?action=delete&id=<?php echo $id; ?>">Delete</a>
  • 4
    You may want to make your answer more clear by posting the correct code instead of the wrong code... – miken32 Mar 31 '17 at 18:33
0

;">Delete delete "()" maybe in php get the "($id)"

zh.ng
  • 16