There are a few errors in that code.
#1 You open the database connection
outside the add function, and then try to use it
inside the function. This doesn't work, because the function operates on a different
Variable Scope.
If you want to use a global variable inside a function, you need to import it using the
global keyword.
<?php
$a = "Hello!";
function foo() {
echo $a; // Prints nothing. Variable $a doesn't exist in this scope.
}
function bar() {
global $a;
echo $a; // Prints: "Hello!"
}
?>
It would be better, in your case, to just open the connection
inside the function, rather then outside it.
#2 The names
Fater'sName and
Email-ID , in your CREATE TABLE command, are illegal. In SQL, the single-quote serves as a string open/close char, and the dash is used as a "minus" sign (for calculations).
If you want to use them in your query, you need to enclose them in back-ticks. (Note these are NOT single-quotes!)
CREATE TABLE `example`(
Field-Name ... -- This is illegal and will cause an error
`Field-Name` ... -- This is OK
);
#3 You don't actually execute either your
CREATE TABLE , nor your
INSERT query.
Although, you do have the
mysql_query call commented out there at the bottom, so I assume you tried it at some point.
#4 $_POST[Button1] should be
$_POST['Button1'] .
Strings need to be quoted, and the name of the element is a string.
Even tho this doesn't cause an error (PHP fixes this in the background) you should still do this right.
O, and P.S.
Please use [code] tags when posting you code. Makes it sooo much easier to read ;-]