The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

now what i have also done is included a delete button. my aim is to tick a box of a record i want deleted, and then click the "delete" button and delete the record....

the trouble i have is actually deleting the specified record... i can delete the whole db... (done many times) but can't select one row.. i'm following a tutorial which is similar and using that as a reference... however i am having trouble using an array approach as seen bellow..

Hi,
I'm a little unclear about your database structure but what I would recommend, if you don't already, is to have a unique key for the table. Make it so every row in the DB table is uniquely identifiable by a number.

You would then use that number, and that number alone to delete the rows. It'd require a simplier query than your current one.

**EDIT**
Sorry for some reason I missed the end of your post about your primary keys. I would still recommend a single numeric primary key. It makes identifying row a lot simplier for the checkbox method, as each value in the returned array contains all the information needed to remove a row.

So on the page that lists your records with the checkbox to delete each, you would give every checkbox the same name (in HTML) with square brackets. You'd also put the value for every checkbox to be the unique ID it has in the number base.
eg. you could run a select query and for each row returned by the query echo a checkbox with name="record[]" and value="$ID" (where $ID is the unique ID from the DB).

Then when the user hits the submit button the $record variable will be an array which will contain each unique ID that has been selected for deletion.
The non-selected checkboxes will not be in the array, it will contain only the IDs that were selected.
You'd then cycle through the array and run a delete query for every value in the array.

Here is sample code to generate your list of records to delete.
It uses field names called 'ID' and 'name' and makes a simple row with the name and checkbox for each.

This would get the $record variable from $_POST, which is an array of all the IDs to be deleted. It would then run a loop through the array, copying the value in each position of the array to the variable $remove and run an sql query to delete that row of the database.

hmmm justing thinking about it more... this script is for bookings of two rooms, and using this unique number they'll will have to know what numbers they can use... is they're an autonumber function similiar to that of access....

hmm.. basically ended up with the same problem as before, ie undefined index.. of record from
$record= $_POST['record'];
i have defined $record, and ['record'].... hmmm *scratching my head*
thanks anyway...
any suggestions? i have a feeling the problem is with

You can set a primary key with a numeric data type to be auto increment, so that every new record will automatically be assigned a value of 1 higher than the existing highest number. If you are using PhpMyAdmin to create or modify your tables you can set the 'extra' drop down box to be auto_increment.

It's hard for my to say what causes your error as I'm not familiar with your project.
What I would suggest though is making a dummy table, nice and simple with just two fields, ID and value . Then build a protoype of your checkbox deleting system to remove records from that table. I often find making little prototypes like that can make tasks easier when you want to apply them to real databases.

no worries, thanks for that... yeh the only thing i didn't like about the unique number was the fact that the customers had to know what number to put in, this auto_increment is what i needed, however it was nice to have my three different fields as primary keys as it reduced data redundancy, and eliminated error of bookings. ie 2 bookings couldn't be made to the same room, same date, same time, however this unique number will disable this... hmmm... i think i will take your suggestion of completing a protoype too, i agree they do help ....

thx for your reply...

- has anyone encountered an undefined index problem
- also my problem say an error ocurred on a line number which is totally irrevelant to the statement

$sql = "DELETE FROM timetable WHERE RoomID ='$array[0]' AND Date='$array[1]' AND Time_Start='$array[2]'";

i had to pass $eventid, to $enventid, otherwise when i refreshed it it didn't like it, because $eventid comes from another page, where there is a calendar, and you click on a date, the date you click on goes into $eventid, then i passed
$enventid = $_GET['eventid'];
currently this is commented out so i don't have to go to the other page for testing....

because that
$sql = "SELECT * from timetable where Date='$eventid'";
statement i couldn't get to work for some reason

so that's why there is an if statement under the first while loop... i know its a bit weird sorry mate, by the i am appreciating your help too...

i got parse error.
actually just noticed double ", oops this php editor i use inserts two " when you type one... stupid thing, now it works but delete still doesn't

also i just commented out the if statement under the first while loop...

if ( "$row[Date]" == "$enventid"){ as i didn't need it because

$sql = "SELECT * from timetable where Date='$enventid'";
worked

<option value="2">SmallRoom
same error as before on the above line... does the lines below seem alright to you... it seems the Date='$array[1]' AND Time_Start='$array[2]'"; is the problem with there indexes... hmmm