sc00tz Posted September 8, 2009 Share Posted September 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/ Share on other sites More sharing options...
ToonMariner Posted September 8, 2009 Share Posted September 8, 2009 http://www.sitepoint.com/article/php-amp-mysql-1-installation/ there's a place to start (you can ignore the 1st part in the series if you have everything installed. Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-914899 Share on other sites More sharing options...
ram4nd Posted September 8, 2009 Share Posted September 8, 2009 you want to use some kind of a cms or start from scratch Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-914902 Share on other sites More sharing options...
bundyxc Posted September 8, 2009 Share Posted September 8, 2009 I'm planning on building a website with PHP and MySQLProbably starting from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-914940 Share on other sites More sharing options...
sc00tz Posted September 8, 2009 Author Share Posted September 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-914963 Share on other sites More sharing options...
mikesta707 Posted September 8, 2009 Share Posted September 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-914979 Share on other sites More sharing options...
ToonMariner Posted September 8, 2009 Share Posted September 8, 2009 sc00tz - go read those articles - try some code and come back when you need some help. Making mistakes is one of the best ways of learning... Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-915058 Share on other sites More sharing options...
sc00tz Posted September 11, 2009 Author Share Posted September 11, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-916868 Share on other sites More sharing options...
bossman Posted September 11, 2009 Share Posted September 11, 2009 you would have to have a 'date' table set up, and have a value inserted into it when entering a form. Then, your query would be something like SELECT * from 'table' WHERE date='$today' Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-916889 Share on other sites More sharing options...
sc00tz Posted September 11, 2009 Author Share Posted September 11, 2009 well i have the NOW() value corresponding with a table i've labeled "timestamp," but the problem is i don't just want it to be based on "today," i want it to basically be anything submitted in the last 8 hours from the current time... Quote Link to comment https://forums.phpfreaks.com/topic/173569-supernoob-question/#findComment-916894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.