FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


mysql/php





shadowozera
Hello everyone, i have been looking for tutorials on teaching the sql script for a user being able to post something on a website.

Example: the script to post an update on a blog page.

I have been searching for some on google with no luck.
Fire Boar
Maybe you're looking too broadly. The steps are as follows:

First, figure out a schema for your database: a table of posts, for example. (Just keep it simple to start with - login details can wait until you have the basics.)

Next, you need to write the CRUD:

- Create: A way of posting new articles.
- Read: A way of viewing existing articles.
- Update: A way of editing existing articles.
- Delete: A way of removing unwanted articles.

The Update and Delete steps are less important than Create and Read, so I suggest doing Create and Read first. They can be done in any order but you won't get anywhere without both.

The Create step involves making a form that the user can fill in. When they submit the form, the contents are parsed and saved to the SQL database using an INSERT query. Investigate the use of POST variables: if in your form tag you have <form action="confirm.php" method="post">, confirm.php will run, and the variable $_POST will be an array of all the form fields and whatever the user filled in.

The Read step involves querying the SQL database with a SELECT statement. Often you'll want to list the titles of several articles, perhaps with a teaser, then have each link to the full page. On the full page, you'll need to use the WHERE clause to filter your results down to just one article. Investigate also the use of GET variables. For example, if your URL is view.php?id=123 then view.php will run, and the variable $_GET['id'] will be set to 123. In this way you can use one PHP file for multiple articles: link to a different ?id=X and in your database schema make sure there is an id field in your article table.

The Update and Delete steps are similar, just like Read you need to identify which article you're talking about, and a GET variable does the job just fine. So have links to update.php?id=123 and delete.php?id=123. Delete is easiest: simply execute a DELETE query. Update is like Create, but you'll find that the form is identical, so why reinvent the wheel? You can use a hidden form field to identify that you're updating an existing article rather than posting a new one and modify the behaviour of your post script accordingly. You'll need an UPDATE query rather than an INSERT one.
spring567
you can go to php.net or mysql.org .
komkom
Fire Boar wrote:
Maybe you're looking too broadly. The steps are as follows:

First, figure out a schema for your database: a table of posts, for example. (Just keep it simple to start with - login details can wait until you have the basics.)

Next, you need to write the CRUD:

- Create: A way of posting new articles.
- Read: A way of viewing existing articles.
- Update: A way of editing existing articles.
- Delete: A way of removing unwanted articles.

The Update and Delete steps are less important than Create and Read, so I suggest doing Create and Read first. They can be done in any order but you won't get anywhere without both.

The Create step involves making a form that the user can fill in. When they submit the form, the contents are parsed and saved to the SQL database using an INSERT query. Investigate the use of POST variables: if in your form tag you have <form action="confirm.php" method="post">, confirm.php will run, and the variable $_POST will be an array of all the form fields and whatever the user filled in.

The Read step involves querying the SQL database with a SELECT statement. Often you'll want to list the titles of several articles, perhaps with a teaser, then have each link to the full page. On the full page, you'll need to use the WHERE clause to filter your results down to just one article. Investigate also the use of GET variables. For example, if your URL is view.php?id=123 then view.php will run, and the variable $_GET['id'] will be set to 123. In this way you can use one PHP file for multiple articles: link to a different ?id=X and in your database schema make sure there is an id field in your article table.

The Update and Delete steps are similar, just like Read you need to identify which article you're talking about, and a GET variable does the job just fine. So have links to update.php?id=123 and delete.php?id=123. Delete is easiest: simply execute a DELETE query. Update is like Create, but you'll find that the form is identical, so why reinvent the wheel? You can use a hidden form field to identify that you're updating an existing article rather than posting a new one and modify the behaviour of your post script accordingly. You'll need an UPDATE query rather than an INSERT one.

I cant Understand!! Sad
zuzu
thank
Fleshy
Fire Boar wrote:
Maybe you're looking too broadly. The steps are as follows:

First, figure out a schema for your database: a table of posts, for example. (Just keep it simple to start with - login details can wait until you have the basics.)

Next, you need to write the CRUD:

- Create: A way of posting new articles.
- Read: A way of viewing existing articles.
- Update: A way of editing existing articles.
- Delete: A way of removing unwanted articles.

The Update and Delete steps are less important than Create and Read, so I suggest doing Create and Read first. They can be done in any order but you won't get anywhere without both.

The Create step involves making a form that the user can fill in. When they submit the form, the contents are parsed and saved to the SQL database using an INSERT query. Investigate the use of POST variables: if in your form tag you have <form action="confirm.php" method="post">, confirm.php will run, and the variable $_POST will be an array of all the form fields and whatever the user filled in.

The Read step involves querying the SQL database with a SELECT statement. Often you'll want to list the titles of several articles, perhaps with a teaser, then have each link to the full page. On the full page, you'll need to use the WHERE clause to filter your results down to just one article. Investigate also the use of GET variables. For example, if your URL is view.php?id=123 then view.php will run, and the variable $_GET['id'] will be set to 123. In this way you can use one PHP file for multiple articles: link to a different ?id=X and in your database schema make sure there is an id field in your article table.

The Update and Delete steps are similar, just like Read you need to identify which article you're talking about, and a GET variable does the job just fine. So have links to update.php?id=123 and delete.php?id=123. Delete is easiest: simply execute a DELETE query. Update is like Create, but you'll find that the form is identical, so why reinvent the wheel? You can use a hidden form field to identify that you're updating an existing article rather than posting a new one and modify the behaviour of your post script accordingly. You'll need an UPDATE query rather than an INSERT one.
IceCreamTruck
This thread is out of order! Smile Please check back soon!
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.