(basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default (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

  2. Similar Questions and Discussions

    1. 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. ...
    2. Basic Forms Authentication Expiration ?
      Yes. When the user is authenticated with FormsAuthentcation.RedirectFromLoginPage or with FormsAuthentication.SetAuthCookie, pass false to the...
    3. 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...
    4. 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...
    5. mysql database fields into html list/menu
      mysql database "myshop" table "einheit" "id" field int(255) auto_increment "name" field varchar(255) =============== = id = name =...
  3. #2

    Default Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)

    Hello,

    On 10/03/2004 02:26 AM, Chris Martin wrote:
    > 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.
    You may want to take a look at this popular form generation and
    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

  4. #3

    Default 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

  5. #4

    Default Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)

    Chris Martin wrote:
    > 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.
    [ ... ]
    >
    > 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?
    Yes, sort of. To be more precise, the submit button sends the data that the
    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 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.
    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" />
    <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.
    >
    > 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!
    It is very powerful. Compared to Java/Oracle, PHP/MySQL is a much simpler
    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

  6. #5

    Default Re: (basic) HTML Forms & PHP to utilize MySql database.. how? (semi-long)

    <snip my OP>
    > Yes, sort of. To be more precise, the submit button sends the data that
    the
    > 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 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.
    >
    > 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"
    />
    > <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.
    >
    Printed it out and going through it line by line to understand how it works!
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139