Adding Text/Image - Simple Admin Interface
This Simple utility allows you to add text and image to a dynamic page from an admin interface via mysql connection using Php.
There are few Requirements which are the following:
- Php version > 4.1.0
- Mysql Version > 4.0.0
You should follow these steps in order to get your script working:
- Create a user and a database (make sure you set up all privileges ex:
mysql> CREATE DATABASE newdb;
mysql> GRANT ALL PRIVILEGES ON newdb.* TO 'newuser'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
),
- Modify the user & database fields in the opendb.php file,
run the admin.php file from your browser and click on the 'Create Tables' link (you can redo it several times to start over if you need),
- Fill in details about the path for the images (input the path of the files) inside the $pathfile variable (addtext.php)
- Click the 'Add text/image' link and fill the form,
- Check out index.php and you are done.
The different Files
- The opendb.php file:
This file is needed to connect to the database. You must fill in the details you entered for the database creation.
Simply copy this to a file and name it opendb.php.
- The closedb.php file:
This file is used to close the database connection.
- The admin.php file:
We could use a login system to access this file but this is not the aim of this tutorial.
Input this inside the body tags of your admin.php file.
- The createtables.php file:
Put this inside the body of your createtable.php page.
The table created can store the listing of an article, a title and the body of the article (the body itself can contain html text).
- The addtext.html file:
This file contains the form to submit to the addtext.php file.
Include the code inside the body of your page.
- The addtext.php file:
This is the file where everything is inserted into the database from the form data. For some tips about the code, check out the comments.
- The index.php file:
Recent articles are added at the top of this page. All the content is displayed dynamically via this file.
Now you should have uploaded all files onto your server inside the same directory.
Run it and use the code wherever you wish.
There is a lot to add to these simple lines if you wish to add features such as comments and several images in a row, the possibility to enhance the user interface of the admin panel (WYSIWYG)... That will be the object of next tutorials.
Comments
No comment yet, write the first now
|