background preloader

PHP Scripts / Snippets

Facebook Twitter

Dynamically Add Input Fields And Submit To Database With jQuery and PHP - InfoTuts. Previously I wrote about adding dynamic input fields in a webpage using jQuery, I got a lot of queries on how to submit it to database.

Dynamically Add Input Fields And Submit To Database With jQuery and PHP - InfoTuts

This tutorial is all about generating input fields on the fly in a web page and submitting the entered data into database. For this tutorial let’s assume you have a registration or survey page which asks user to enter his hobbies (hobbies can be multiple). Some have two hobbies and some may have ten, so we will let them enter as many hobbies they want. You can use this tutorial to build more user friendly forms which collect data from users. Let your users create fields on the fly and enter data. Download Code I have created a sample database “hobbies” having one table “my_hobbies”. SQL query for hobbies table: To connect with database I have created a separate “dbconn.php” file which contains hostname, mysql username and mysql password to connect with database. Code for dbconn.php: Code for index.php:

The perfect PHP clean url generator. Automatically post to Facebook from PHP script. Pagination with a PHP class - David Carr - Web Developer Hull. I’ve recently wrote a pagination class for php, I used to do this in a procedural way by using functions, it’s always worked fine, but its not as reusable as a class is. I’ve released this class on Github this tutorial will explain how to use the pagination class. Include the classcreate a new instance of the class, set the number of records by page and a referenceThen set the total number of records, do this by either setting in manually or by counting records from a datasetSet the total number of records by passing the total to the method set_total()Then display the records as normalTo show the page links echo page_links() optionally passin 2 parameters the first set the address by default this is ? The second parameter is for any $_GET’s you want to pass from page to page. Download the class from Github Like this: Like Loading...

Reading events from an iCal Calendar using PHP - David Carr - Web Developer Hull. Generate a PDF from a web page - David Carr - Web Developer Hull. Dynamically binding select menus with PHP & jQuery - David Carr - Web Developer Hull. I’ve recently had the need to show different select menus depending on what was selected in the first select menu, this guide will explain how to achieve this quickly. See the demo for a working example. In my example I have two tables books and book_categories, the categories table holds all the categories the demo will use namely: CSSjQueryHTMLPHP The books table holds a list of books each book belongs to a specific category the structure of the books table is as follows: books_categories: How does it work? The first select menu lists all the categories then when a selection is made an ajax request is made via jQuery to change.php. Getting Started First inside a form tag, create a select menu inside the menu populate the options with the book categories <p><label>Book Type:</label><select name='catID' id='catID'><option value=''>Select</option><?

Give the select menu an id for jQuery to use later in this case I used catID for both the name of the select and its id. Change.php <? Index.php.