Jump to content

Updating and deleting data in MySQL tables using PHP


tracy

Recommended Posts

Assuming I have a table named 'table' with the following categories:  one, two, three, four, five, six, seven,eight...
and that I can connect to the MySQL database and enter data into same table through PHP...

How would I write the code to display the contents of the table with a 'check box' beside each entry so that I could 'check the box' beside any entry and edit it or delete it.

And secondly, how would I actually generate the PHP page that would allow me to delete or edit the entry after I 'select' it from previous? 

Kind of new to PHP, so thanks for any help. 

I would ideally like a page with the options of add, edit and delete...and when the appropriate 'button' is clicked, the proper php page displays to allow me to make the changes.  I can do the add page, no problem.  I just have trouble with the edit and delete part.  Ideally, I'd like the table contents to display on a page when I click edit or delete (which can be the same button)...then I could 'check the box' next to the item to be edited or deleted and taken to that item's display page for editing or deleting...or something like that.

I understand that a select query has to be done to 'get' the item for editing or deleting, but would like that process handled in a table format with a check box for selecting that item...

Thanks.
Link to comment
Share on other sites

I'm not asking for someone to code it for me...thank you.

I can't believe you'd actually take the time to post that remark.  I wouldn't post here without researching it extensively both in print and on the internet...

Anyway, what I'm hoping to find is someone kind enough to point me to a tutorial that actually works.  Or maybe a suggestion on one or two of the specific problem areas:

1.  Creating the display table with the check box option
2.  Telling me which files are needed to make it work...for example, one file for the edit/delete, or one file for edit, one for delete...

etc.

Thanks.  Again, kinda new to PHP...looking for info, not non-constructive criticism.

Link to comment
Share on other sites

If you haven't yet got a working apache / php / mysql installation, I'd start by installing XAMPP.

After ensuring the installation is working correctly, the first thing I'd try and do is create a simple HTML form.  One that has a few fields (not necessarily checkboxes) that you can enter information into.  For the form handler, just try and output what was submitted.

That's the first thing I'd do in your shoes.
Link to comment
Share on other sites

I can actually (and have already done it) create a MySQL database, use PHP to insert data into it and have it print out a table to the browser containing the data in the database.  I'm now at the stage of trying to write the PHP for deleting items and/or editing them.

The problem is that rather than having to know which item to edit/delete, I'd like to have a table display the data in the table with a check box in one column next to each row.  Then the item that is 'checked' is the item SELECTED for edit or delete. 

This check box being displayed is the problem I'm having.  I think I could make another 'column' in the database that is true or false depending on whether the box is checked, but when trying to incorporate all this into html, PHP and MySQL it gets kinda complicated.  I would therefore like a tutorial to view and get a better understanding of it.  Or perhaps an explanation of the basic concept so that I could research it more...like what the correct terminology is for a check box imbedded in a database generated by MySQL and PHP and HTML...

I know that I have to query the database table and cause it to be printed to the browser.  I then know that I have to write the commands for the PHP to cause the MySQL to SELECT the data linked to the checkbox...that's what I'm unclear about...if I knew how to SELECT based on the check box I feel I could generate the proper code. 

Thanks.
Link to comment
Share on other sites

Here's a hint on the terminology to get you started.  You're talking about creating an HTML form with check boxes for input.  I'd start here:
http://www.echoecho.com/htmlforms.htm

Forget about the database stuff for now, just work on creating and displaying a form with checkboxes.  Then try and set it up so you can submit it and echo the output.

When you get that far, or get stuck in the process, come back to this thread and I'm sure you'll get more help.

(EDIT) When I say create a form with check boxes, just disregard whats in your database or what you think the end form will look like.  Keep it simple and focus on the single task at hand:
Creating an HTML form and successfully getting data from it.

(EDIT #2) This might give you head start:
http://www.phpfreaks.com/forums/index.php/topic,115088.msg468702.html#msg468702
Don't just copy and paste that.  Dissect it and figure out why it does what it does.
Link to comment
Share on other sites

I might be misunderstanding you, but I think I have already done that.  I can create a form and use it to add data to the MySQL database.  I can then print that database back to the browser showing what data I just added plus all the previous data.  Just like it should, no problem.

I understand how to make a form using html also--with a checkbox. 

What I'd like info regarding is how to write the specific few lines of code that tells the PHP/MySQL that the item with the check in the box is the item selected for edit or deletion.  Any thoughts?
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.