Page 1 of 1

PHP and MySQL for database driven site

Posted: Sun Oct 14, 2007 9:29 pm
by koskilla
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I need some help with my web site... I am pretty new to the whole server side programing stuff. I've done mostly HTML and non-web stuff like VB and ADO etc. Anyways... I have used mysql for some VB stuff and was wondering if it was the best thing to implement with my new site.

I have a site, where I want it to grab all text from a database. I want to add the text through a private form.

Here is the code for the form that I have:
Code:
[syntax="html"]<h4 class="top">Add page...</h3>
<form name="blogarchiveform" id="blogarchiveform" action="">

<br><br>Photo path
<input class="button" type="file" name="done" value="done" />

<br><br>Thumbnail path
<input class="button" type="file" name="done" value="done" /><br /><br />

   <label for="text">Category:</label><br />
   <textarea id="text" name="text"style="height:3"></textarea><br /><br />
   
      <label for="text">Date:</label><br />
   <textarea id="text" name="text" style="height:17px" cols="20"></textarea><br /><br />
   
         <label for="text">Month: <i>August 2007</i></label><br />
   <textarea id="text" name="text" style="height:17px" cols="20"></textarea><br /><br />
   
      <label for="text">Time:</label><br />
   <textarea id="text" name="text" style="height:17px" cols="20"></textarea><br /><br />
   
      <label for="text">Title:</label><br />
   <textarea id="text" name="text" style="height:17px" cols="50"></textarea><br /><br />
   
<br /><br />Write a comment<br />
   <label for="text">Comment:</label><br />
   <textarea id="text" name="text" rows="10" cols="50"></textarea><br /><br />
<br />
<input class="button" type="submit" name="post" value="Send" />

</form>
The thing is, I know next to nothing about how forms work, so I need some specific direction. I want this data to be put into a database, and then I need some code or something that takes the data out and puts it in the webpage.

Can anyone tell me how to do this, or if MySql is even the way to go? I'm currently using PHP, btw.

If anyone is willing to talk to me over IM to help me, I would appreciate that as well.

Thanks so much in advance. I really appreciate your time


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Oct 14, 2007 11:53 pm
by Christopher
A few basics:

- Post the form page to itself, not a separate page.
- Get the form values from the $_POST superglobal variable.
- Filter and validate the values before using them (learn preg functions)
- Escape values before outputting them (htmlentities() for HTML, database specific escape() )
- Redirect to a "done" page if all values are acceptable

Posted: Mon Oct 15, 2007 4:01 pm
by califdon
You're really asking for an entire tutorial on HTML forms, PHP and MySQL -- you'll need a lot more than we can provide in a forum. arborint's suggestions are good ones, but you will obviously need to learn A LOT of details. I would suggest that you might start with some online tutorials at a comprehensive site like http://www.w3schools.com/, where they have tutorials, references and examples on just about every imaginable language and technology.

Posted: Mon Oct 15, 2007 7:10 pm
by shannah
I developed Dataface to make this sort of thing easier. http://weblite.ca/dataface .
Using dataface you would basically create your database tables with the correct fields - then it handles all of the form processing and searching etc..

Posted: Mon Oct 15, 2007 10:39 pm
by RobertGonzalez
But that would take all the fun out of learning.

I would suggest downloading the sample chapters of Kevin Yank's Sitepoint book "How to build your own database driven using PHP and MySQL". Search sitepoint.com, you can't miss it.

Quite literally the free four chapter download can get you to the point where you know how to set up a database, how you connect to one, how to select, insert, update and delete data and how to interact with your database using forms. It is a great tutorial for beginners. I highly recommend it.