Jump to content

PHP MySQL Alter and Delete Script


Darno

Recommended Posts

Sir/Ma'am,

    I'm newbie programmer in php. I'm working with a Purchasing System using a php and MySQL. I have created a delete script in a said System but it could only delete 1 record...Please give some suggestions or ideas on How do I delete a record one by one and give some scripts in altering a record..tnx a lot.. :) 
Link to comment
Share on other sites

Your question is not at all clear to me.

You state that you have been able to delete a record. So you know how to do this. Just repeat it (with a different WHERE clause of course) for the other records you want to delete.

About altering: you can ALTER a database or ALTER a table, but what do you mean by ALTERing a row?

Ronald  8)
Link to comment
Share on other sites

Suppose you have listed several items from a table, and have a checkbox on each row to indicate which items are to be deleted
[pre]
Item              Qty        Delete

Widget            25          (x)
Wotsit              1          ( )
Gizmo              10          (x)

                (Delete selected)[/pre]
               
Define each c/box with a name ending with "[]" and with a value = the id of the listed item
EG
[code]echo "<input type='checkbox' name='delitem[]' value='$id'>";[/code]

When the form is submitted you want to create a query like

DELETE FROM item WHERE id IN (1,3)

which will delete the 2 items shown above.

[code]<?php
$items = join (',' , $_POST['delitem']);
mysql_query ("DELETE FROM item WHERE id IN ($items)");

echo "Selected items deleted";
?>
[/code]
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.