How can I add, edit, and delete database records in Drupal?
I have a list of records in a MySQL database table. Each record is for one news item. The table has columns for id, date, summary text, and external URL. The items are entered manually, not through any RSS feed.
I need authorized users to be able to update that table, e.g. add, edit, and delete records. Classical situation for an HTML
<
form> generated by PHP. I've done it many times in PHP. Is there a way to do it in Drupal web pages (e.g. the form in a block)? Or must I create a link leaving the Drupal site, run a PHP module to create the form, then another PHP module to accept the input values and which links back into the Drupal site? I can see how to create the form in a Drupal page, but I can't see how to receive the form's input values in another Drupal page.
Comments
The Drupal way of doing it
The Drupal way of doing it would be using Form API to create the form, and then make a call to db_write_record() with a submit callback. As for the permission, you could either use the Menu System to control, or you could validate when user is trying to submit the change. You may find it cumbersome to go through all these readings (I mean it... each of these components can be a chapter of it's own), however the real benefit of this architecture is the enhanced security instead of making your development easier (though I do think so too once I got to be more familiar with the concept).
But of course, you could always go back to the php way and build all DB connection from scratch, and risk of paying the price to handle the security risks that these user input fields will bring you.
Just my 2 cents :)
Kelvin Lee
Onion Creative
Twitter: @KelvinLeeHK | @OnionCreativeHK
Google+: +Kelvin Lee
Or just forget your table and
Or just forget your table and re-create the whole thing with CCK. All the fields will remain in one table as long as you don't share fields with other content types, or have multi-value fields. Even better use Webform module which throws in email notifications and exportability for free. I'm guessing you could do the whole thing with Webform in about 30mins.
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his