PDA

View Full Version : Issue about form submission and my database.


atticus589
05-26-2008, 06:02 AM
Okay, so I started off thinking I could submit forms to be viewed online via HTML. Then I get pointed to PHP, and now I am at SQL.

Simply put,
I want to have a user log in, fill out a form, have the form saved to a MASTER file, and the users file.

I want the user to be able to view HIS file, no other users files, I want the master account to be able to view the masterfile.

NOW... I understand that the majority of that is written in html, that I can accomplish. The part that I am having trouble figuring out is the, "action" meaning the part where It saves the information that is entered into the form for later use. I was referred to SQL for that. So I looked up SQL, and it seems there is a language and a few programs for SQL, and this is where I am confused. If I want to implement SQL into my website do I have to buy a program or how do I get the SQL database setup?

Explanation isn't necessary tutorials work for me.

Fumigator
05-26-2008, 06:23 AM
SQL is a language-- that's what the "L" stands for ;), it's the Structured Query Language. It's not a language in the classic sense though-- meaning, there's no compiler and it's not sold and/or owned by any one company. I guess you could look at it as more of a group of standard syntax rules that database engines, such as MySQL, SQL Server, DB2, Oracle, etc, use to access and manipulate data in a database. And these databases typically aren't free; MySQL is the exception, hense the popularity of MySQL.

So what you'll need to do is choose a database engine first. MySQL is an easy choice; nearly every hosting company offers access to a MySQL database. And then you'll want to grab an introductory book and/or use Google to research and learn how to use a database with a web page.

The tricky part is, you are talking about a combination of tools needed to get the job done, so you have to become at least somewhat knowledgable with each tool to succeed. (HTML, PHP, MySQL, and perhaps Javascript)

If you want to tackle each tool separately, you may want to skip the SQL thing at first and just focus on PHP. With PHP you can write and read normal files, which is a more straight-forward way of saving and retrieving information from an HTML form. Flat files don't have the flexibility and power of a relational database such as MySQL, but they can get the job done.

To directly answer your question, the "action" part of saving form data to a MySQL database using PHP would look something like this. The INSERT command is standard SQL syntax; the PHP functions work only with MySQL.


$query = "INSERT INTO person_table (name, address, phone) VALUES ({$_POST['name']}, {$_POST['address']}, {$_POST['phone']})";
$result = mysql_query($query);
if (!$result) {
die("SQL error encountered. Query: $query<br>Error: " . mysql_error());
}

atticus589
05-26-2008, 06:29 AM
I've got HTML under control its fairly simple, atleast what I am using it for it is.

You did answer alot of the questions that I needed answered.

a form processing script will be what I use to save the information to an SQL database.

Do you possibly know of like a 10mb hosting site that is free that allows me to use MYSQL? So that I can start testing the scripts I put together? Or do you know a program that would allow me to make basically a fake website that only I could access so that I can get my idea working?

Fumigator
05-26-2008, 06:33 AM
You can install Apache, PHP, and MySQL on your own Windows maching using a WAMP installer such as XAMPP (http://www.apachefriends.org/en/xampp.html).

atticus589
05-26-2008, 06:42 PM
I installed Xamp I am just not sure what all of it is...

I was hoping it was a directory emulator, where I could throw all the Php's HTML's and SQL's into a directory on my desktop and use it to fake a website so that I could makesure everything is working. NVM. I got it figured out... Sorry I have downs.

atticus589
05-26-2008, 07:12 PM
I have all my thing setup, login, brings you to your form, fill out the form. I use a PHP to send the forms contents to my SQL. now how do I access the forms from MYsql?

Fumigator
05-26-2008, 11:55 PM
Your access to form data is via PHP's $_POST and/or $_GET arrays.

atticus589
05-27-2008, 02:19 AM
Say I wanted to display a variable saved in the "name" column. I am not sure what the table name is... what would I display that with?

Fumigator
05-27-2008, 05:03 AM
You have to know the names of the tables in your database, then you'd use a SELECT query to select and display the rows in the table. SELECT name FROM table1