Jump to content

supernoob question


sc00tz

Recommended Posts

I'm planning on building a website with PHP and MySQL, but I have no experience with either at this point.  I'm wondering if someone can at least set me down the right path so I don't waste money on some books that I can't use.

 

I need to build a site with a few simple functions.

- People need to be able to signup for an account and subsequently login to the site

- Once logged in, there will be a form people fill out as many times as they want; let's say for the sake of brevity that each form will have 1 pulldown menu with about 100 choices, and then 4 text fields for the user to fill out

- The form gets submitted to a database, where each form submission has its pulldown choice, its 4 text field entries, as well as the time of submission and the username under which it was submitted

- On another page,  I would like users to be able to search all forms submitted for certain words or to sort by either time or pulldown choice

 

What exactly do I need to do to accomplish this and how do PHP and MySQL interact in this context?  Any help would be immensely appreciated, and although I do have some coding experience, I am completely illiterate in this medium.

Link to comment
Share on other sites

my understanding is that if i used a cms i would probably have to pay someone to set it up, and id rather do the whole thing by myself since as far as i can the entire system should be relatively simple (basically a glorified discussion board).

 

i understand how to write code and some of the basic ideas of PHP, i just don't really understand in laymen's terms exactly how PHP and MySQL interact to create the pages that i want users to be able to login and see

Link to comment
Share on other sites

Well, basically PHP connects to a mysql database. Once in that database, it can interact with certain tables. PHP does what are called "queries" which are basically commands written in the sql language. For example, if you wanted to select everything from a table, the query would look like this

SELECT * FROM table

 

additionally, if you wanted to only retrieve two columns from a table the query would look like this

SELECT column1, column2 FROM table

 

However, for something like a login system, you only want to pull data from the table if it matches certain columns, say... the username and password column. well a query for the user joe with password pass would look like

Select * from table WHERE username='joe' AND password='pass'

assuming that the column that stores usernames is called "username" and the column that stores passwords is called "password". Simple enough right?

 

Now where does PHP come in all this? Well, SQL doesn't really have variables in the sense that php does. But since you can run Mysql queries in PHP, you can also use PHP variables in those queries. So say you wanted to select everything from a table, but you wanted to store that table in a variable so you could save it for use in another script. Well you could do

 

$table = "myTable";
//now the query
//the syntax for a mysql queries goes as follows
//do the query via the mysql_query() function
//retrieve the results with mysql_fetch_array() or
//one of the other retrieving functions
$result = mysql_query("SELECT * from ".$table);
//note how we used the variable in the query

 

Simple enough right? Now if we wanted to retrieve the row for a specific user, we would so something like

$user = 'Joe';
$pass = "pass";

$query = mysql_query("Select * From $table Where username='$user' AND password='$pass' LIMIT 1");
//limit 1 limits the amount of rows returned to 1
//now we get the array
$row = mysql_fetch_array($query);
//to access the info from the row we use the column names as keys for the array.
//to greet the user we would do
echo "Hello: ".$row['username'];

 

Pretty simple right? And you could instead of hardcoding values into the variable, assign them to post variables, or whatever you want really. I suggest you google some simple PHP mysql tutorials to get the hang of how they interact, and once you understand, building what you want to build would be quite easy and fun! Hope that helps

 

 

Link to comment
Share on other sites

thanks for the help guys!

 

okay so i've got a database set up and the forms are working fine but i'm having a bit of trouble setting up the page where i want the actual information revealed.  i included the mysql NOW() timestamp with each form submitted.  but now i'm trying to create a page where only the datasets with timestamp for a certain date are displayed, and if there are none to have a message that explain this.  i can't figure out exactly how the NOW() values work though...any advice?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.