Log in

View Full Version : Begginer - creating a table



mrabin
09-01-2010, 03:43 AM
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:



<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:



// 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

traq
09-01-2010, 04:17 AM
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.


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.

mrabin
09-01-2010, 08:15 AM
exactly what I needed. Thank you