I make a delete page with php to delete clients from clients table. With this page I try to delete images from gallery table. for example I wish to delete client ABC from clients table and it have three images in gallery table.

here under I paste the code to delete the specific client and images, when I hit the delete button it goes to deleteclientpage but the specific client and images doesn't delete.

can anyone give me some help to make it work?

if (!empty($_GET["clientid"]))
        $clientid = $_GET["clientid"];
        $query = "DELETE FROM clients, gallery WHERE clients.clientid = $clientid AND gallery.clientid = $clientid";
        //change the way the query is called

        echo "<p id='text'>The client was deleted.</p>";


Recommended Answers

All 8 Replies

Do you get an error?

echo $query

and tell us what results do you get.

echo $query;

pritaeas and thirsty.soul it dosn't show anything either with echo $query; or not.

Check your error log, or add error checking to the execution of your query.

to cover the basics:
make sure $_GET["clientid"] is not empty
add: else echo "no clientid";

it means that
if (!empty($_GET["clientid"])) is not executing. share HTML,

I check my coding for another time and I solved it regarding to the begining of if statment because in a href name it id instead of clientid but when I try again to delete the page shows me this error shown below

4You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE clients.clientid = 4 AND gallery.clientid = 4' at line 1

as your code i understand. you have two table client and gallery. gallery have clientID for its Images. so u can do this way

first you checked in your URL There is a clientid or not without clientID code not work

    if (isset($_GET["clientid"]) || $_POST["clientid"])
    $clientid = $_GET["clientid"];
    $query = "DELETE FROM clients WHERE clientid ='".$clientid."'";
    $query1= "DELETE FROM gallery WHERE clientid ='".$clientid."'";
    echo "<p id='text'>The client was deleted.</p>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.