PHP and MySQL for database driven site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
koskilla
Forum Newbie
Posts: 3
Joined: Sun Oct 14, 2007 9:23 pm

PHP and MySQL for database driven site

Post 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]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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
(#10850)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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.
shannah
Forum Newbie
Posts: 13
Joined: Mon Oct 15, 2007 1:01 am

Post 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..
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply