Results 1 to 3 of 3

Thread: Begginer - creating a table

  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Begginer - creating a table

    I'm very new to all this so I don't know much. just have a couple questions. I am trying to make it so that when I click submit on my webpage form (http://www.unlikerabi.com/instructor/signup.html), that the information is passed to the mysql server and put into a table.

    Moving on to the questions:

    Because practice.php is called every time someone clicks the submit button, does that mean that mysql will try to create a new table every time? If it does, how do i implement practice.php so it only creates the table once?

    Is it possible for anyone to see my PHP?


    Here's the relevant HTML:

    Code:
    <h1>Where would you like to find a swim instructor?</h1>
    
    <form name="sample" id="sample" action="php/practice.php"
    method="post">
    and the practice.php:

    Code:
    // connect
    $con = mysql_connect("localhost","###","###");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    // Create table
    mysql_select_db("###", $con);
    $sql = "CREATE TABLE Persons
    (
    FirstName varchar(15),
    LastName varchar(15),
    Age int
    )";
    
    // Execute query
    mysql_query($sql,$con);
    mysql_close($con);
    Thanks
    Last edited by djr33; 09-01-2010 at 03:48 AM. Reason: fixed [/code] tags

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,634
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by mrabin View Post
    Because practice.php is called every time someone clicks the submit button, does that mean that mysql will try to create a new table every time? If it does, how do i implement practice.php so it only creates the table once?
    In this case, yes. The code you use to create the database table should be in it's own script, so it's only run when needed.

    Actually, a much simpler solution is to use something like phpMyAdmin to create databases and build your tables. Most hosts that offer databases also provide phpMyAdmin (or a similar program). It's very easy to use.

    Your webpage form should be limited to processing the visitor's responses and submitting the info to the database.
    Quote Originally Posted by mrabin View Post
    Is it possible for anyone to see my PHP?
    If your host is set up correctly, no. PHP is processed by the server, and only the script's output is sent to the user.

  3. The Following User Says Thank You to traq For This Useful Post:

    mrabin (09-01-2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    exactly what I needed. Thank you

Bookmarks

Posting Permissions

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