Ask a Question related to PHP Development, Design and Development.
-
Chris Martin #1
(basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)
Background:
I have 6 books and way to many websites open in front of me. It's time for
bed, and I'm missing real human contact (you know, you get involved with a
project and you stop talking to people)? So my current project is getting
my work's schedule posted online. I work in a resturaunt and what I'm
trying to do is put up the schedule that comes out once a week for all
employees on the internet. At the moment I'm scanning in the one (sometimes
two) page(s) and putting them up in a strictly html webpage.
Problem: This is not secure (allows anyone to see our schedule and it most
likely breaks some anti-privacy laws somewhere). Also, this method does not
allow for any custumization on a user level.
Solution: Use a database of members, giving each member username and login
information (to begin with) and also will hold information for later
custumization ideas.
What I have done: I have a webpage. MySQL (4.0.20-standard) is installed
and I've been using phpMyAdmin. The website is using PHP version 4.3.8. I
have created a Database (MemberDirectory), and a table in that database
called (Members). The important fields in this are loginName, password,
lastName, firstName, and phoneNumber.
What I would like to do: Allow a person to create a new member (row in the
table) and set up those fields, then be able to use that information to
login to a members only page.
Trouble I'm having: I've looked at tutorials and books, and I see too many
ways to do this. At the moment, in my mind, the best way to do this is to
set up an HTML document with a form, and the submit button activates a PHP
file which updates the MySQL database. That is what I have gathered to be
one way to do what I am attempting, am I correct? And if I am, What would
the PHP file look like? The books and tutorials give snippits of code for
individual parts, but as I'm trying to impliment this its the parts that are
not shown that I'm getting confused on.
This is longer than I wished it to be, so I'll stop now and hopefully bring
up more topics if this turns into a thread. If you're still with me, thanks
for reading this far, even if you cannot help me!
~Chris Martin
So far I've had two days to teach myself the theory of PHP and MySQL, and
I'm certainly looking forward to using it as a powerful tool once I can!
Chris Martin Guest
-
Forms Basic
Hi I am new to Macromedia... Trying to build a simple form that has Dynamic Text fields, Numericstepper, calendar, check box, email field etc. ... -
Basic Forms Authentication Expiration ?
Yes. When the user is authenticated with FormsAuthentcation.RedirectFromLoginPage or with FormsAuthentication.SetAuthCookie, pass false to the... -
Basic Forms Authentication question
I can't get this damn thing to work at all. I have a virtual directory set up with anonymous access only, web.config contains the following but... -
php and html forms: select multiple default selected from php/mysql
hi, i'm pretty new to all this, so bear with me.... i want to call from the database the total number of options for a select box (from table... -
mysql database fields into html list/menu
mysql database "myshop" table "einheit" "id" field int(255) auto_increment "name" field varchar(255) =============== = id = name =... -
Manuel Lemos #2
Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)
Hello,
On 10/03/2004 02:26 AM, Chris Martin wrote:You may want to take a look at this popular form generation and> What I would like to do: Allow a person to create a new member (row in the
> table) and set up those fields, then be able to use that information to
> login to a members only page.
>
> Trouble I'm having: I've looked at tutorials and books, and I see too many
> ways to do this. At the moment, in my mind, the best way to do this is to
> set up an HTML document with a form, and the submit button activates a PHP
> file which updates the MySQL database. That is what I have gathered to be
> one way to do what I am attempting, am I correct? And if I am, What would
> the PHP file look like? The books and tutorials give snippits of code for
> individual parts, but as I'm trying to impliment this its the parts that are
> not shown that I'm getting confused on.
validation class.
The way the examples work is that you define, output and process the
forms in the same script.
If the form is being presented for the first time, the script just tells
the class to display the form.
If the form is being submitted, the script asks the class to load and
validate the submitted form values.
If all fields are valid, the script just does something to process the
form, otherwise the form is presented again along with an error message
telling the user why the form is not valid.
[url]http://www.phpclasses.org/formsgeneration[/url]
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
[url]http://www.phpclasses.org/[/url]
PHP Reviews - Reviews of PHP books and other products
[url]http://www.phpclasses.org/reviews/[/url]
Metastorage - Data object relational mapping layer generator
[url]http://www.meta-language.net/metastorage.html[/url]
Manuel Lemos Guest
-
Patrick McDonnell #3
Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)
You may want to have a look the PEAR modules for AUTH - I believe they can
talk to MySQL. Maybe part of what you're looking for.
Patrick McDonnell Guest
-
Rajek #4
Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)
Chris Martin wrote:
for> Background:
>
> I have 6 books and way to many websites open in front of me. It's time[ ... ]> bed, and I'm missing real human contact (you know, you get involved with a
> project and you stop talking to people)? So my current project is getting
> my work's schedule posted online.
many>
> Trouble I'm having: I've looked at tutorials and books, and I see tooYes, sort of. To be more precise, the submit button sends the data that the> ways to do this. At the moment, in my mind, the best way to do this is to
> set up an HTML document with a form, and the submit button activates a PHP
> file which updates the MySQL database. That is what I have gathered to be
> one way to do what I am attempting, am I correct?
user entered into the form to the URL in the form element's "action"
attribute. That URL could be a PHP file (e.g., "updateDB.php"). The PHP file
contains code that turns the name-value pairs sent from the <form> into an
SQL statement that updates your database.
And if I am, What wouldare> the PHP file look like? The books and tutorials give snippits of code for
> individual parts, but as I'm trying to impliment this its the parts thatHere's an example of a complete "add a row to a DB table" type PHP file.> not shown that I'm getting confused on.
----------------------------------------------------------------------------
-
EXAMPLE
----------------------------------------------------------------------------
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Article output</title>
<meta http-equiv="Content-type" content="text/html; charset=us-ascii" />
<meta http-equiv="Content-Language" content="en-us" />
<meta name="ROBOTS" content="NONE" />
<style type="text/css">
/*<![CDATA[*/
@import url(/admin/css/admin.css);
/*]]>*/
</style>
</head>
<body>
<pre>
<?
insertDB();
?>
<!-- Removed some code here not needed for this example. -->
<?php
function insertDB()
{
$con = mysql_connect("YOUR_MYSQL_HOST", "YOUR_MYSQL_USERNAME",
"YOUR_MYSQL_PASSWORD");
if (!$con)
{
echo "Error connecting to DB";
}
mysql_select_db("articles");
$statement = "INSERT INTO articles VALUES (
'" . trim($_POST["copy"]) . "',
'" . trim($_POST["notes"]) . "',
'" . trim($_POST["general_refs"]) . "',
'" . trim($_POST["category"]) . "',
'" . trim($_POST["title"]) . "',
'" . trim($_POST["subtitle"]) . "',
'" . trim($_POST["author_01_name"]) . "',
'" . trim($_POST["author_01_linktarget"]) . "',
'" . trim($_POST["author_02_name"]) . "',
'" . trim($_POST["author_02_linktarget"]) . "',
null,
'" . trim($_POST["date"]) . "',
'" . trim($_POST["photo"]) . "',
'" . trim($_POST["photo_alt_text"]) . "',
'" . trim($_POST["photo_credit"]) . "',
'" . trim($_POST["photo_credit_link_target"]) . "',
'" . trim($_POST["filename"]) . "')";
$result = mysql_query($statement);
}
?>
</body>
</html>
Hope that helps. I imagine others will have comments and criticsms of the
above code. So you might want to wait for that before using it :) But it
does work in my application.
bring>
> This is longer than I wished it to be, so I'll stop now and hopefullythanks> up more topics if this turns into a thread. If you're still with me,It is very powerful. Compared to Java/Oracle, PHP/MySQL is a much simpler> for reading this far, even if you cannot help me!
>
> ~Chris Martin
>
> So far I've had two days to teach myself the theory of PHP and MySQL, and
> I'm certainly looking forward to using it as a powerful tool once I can!
programming environment. However, it is powerful and I've found that it's
complicated enough and contains many "gotchas".
The best PHP book I know of is PHP and MySQL Web Development by Welling and
Thompson from SAMS publishing house.
Rajek Guest
-
Chris Martin #5
Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)
<snip my OP>
the> Yes, sort of. To be more precise, the submit button sends the data thatfile> user entered into the form to the URL in the form element's "action"
> attribute. That URL could be a PHP file (e.g., "updateDB.php"). The PHPfor> contains code that turns the name-value pairs sent from the <form> into an
> SQL statement that updates your database.
>
>
> And if I am, What would> > the PHP file look like? The books and tutorials give snippits of code--> are> > individual parts, but as I'm trying to impliment this its the parts that>> > not shown that I'm getting confused on.
> Here's an example of a complete "add a row to a DB table" type PHP file.
>
> ----------------------------------------------------------------------------> -
> EXAMPLE
> --------------------------------------------------------------------------/>> -
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
> <head>
> <title>Article output</title>
> <meta http-equiv="Content-type" content="text/html; charset=us-ascii"Printed it out and going through it line by line to understand how it works!> <meta http-equiv="Content-Language" content="en-us" />
> <meta name="ROBOTS" content="NONE" />
> <style type="text/css">
> /*<![CDATA[*/
> @import url(/admin/css/admin.css);
> /*]]>*/
> </style>
> </head>
>
> <body>
> <pre>
> <?
> insertDB();
> ?>
>
> <!-- Removed some code here not needed for this example. -->
>
> <?php
> function insertDB()
> {
> $con = mysql_connect("YOUR_MYSQL_HOST", "YOUR_MYSQL_USERNAME",
> "YOUR_MYSQL_PASSWORD");
> if (!$con)
> {
> echo "Error connecting to DB";
> }
> mysql_select_db("articles");
> $statement = "INSERT INTO articles VALUES (
> '" . trim($_POST["copy"]) . "',
> '" . trim($_POST["notes"]) . "',
> '" . trim($_POST["general_refs"]) . "',
> '" . trim($_POST["category"]) . "',
> '" . trim($_POST["title"]) . "',
> '" . trim($_POST["subtitle"]) . "',
> '" . trim($_POST["author_01_name"]) . "',
> '" . trim($_POST["author_01_linktarget"]) . "',
> '" . trim($_POST["author_02_name"]) . "',
> '" . trim($_POST["author_02_linktarget"]) . "',
> null,
> '" . trim($_POST["date"]) . "',
> '" . trim($_POST["photo"]) . "',
> '" . trim($_POST["photo_alt_text"]) . "',
> '" . trim($_POST["photo_credit"]) . "',
> '" . trim($_POST["photo_credit_link_target"]) . "',
> '" . trim($_POST["filename"]) . "')";
> $result = mysql_query($statement);
> }
> ?>
> </body>
> </html>
>
> Hope that helps. I imagine others will have comments and criticsms of the
> above code. So you might want to wait for that before using it :) But it
> does work in my application.
>
I appreciate the code. I have never used a CSS (that's a cascading style
sheet, correct?). Do I need to have anything enabled on my server to accept
this? believe not, but it's always better to ask. I've also never used
xhtml, is that like xml? Gonna do a bit of research before I start asking
lots of questions I can answer myself with a quick google search, thanks
again.
~Chris
Thanks also to the other responses I've gotten. I was just able to get to
my computer a few moments ago, (had to free a snake that got caught up in a
net in my yard.. fun).
Chris Martin Guest



Reply With Quote

