I'm very new to php and I'm trying to insert some information from a form into my database. Right now, my form handling script is on the same page as the form and I'd prefer to keep it that way. My problem is that when I run it, I always get the same error....that there's an undefined variable. I've cut the script down into it's most basic form and here it is.
<?php
require_once('Connections/connJF.php');//connects to database
mysql_select_db($database, $conn) or die ("Could not open database.");
$sql = "INSERT INTO applicants (first_name) VALUES ('$first_name')";
?>
I think my problem might be what I should be putting as the form action; I know that it must be simple, but I'm not seeing it. The error message I'm getting is indicating that it's not recogizing "first_name" as a variable in my $sql line. This is the name of the field in the form however. Does it matter where this script is placed when it runs on the same page?
While I'm on the subject, what's the difference between using variables from forms as $variable versus the $HTTP_POST_VARS method? Thanks.
$sql = "INSERT INTO applicants (first_name) VALUES ('".$first_name."')";
It's not incorrect - you can have variables within a double quoted string without concenating them. With syntax highlighting though, concentation can make finding your variables easier.
I'll make those changes and see what happens. In the meantime, can someone tell me what the proper syntax is for the form action when the script that is handling the form is in the same file as the form itself? I think PHP_SELF is involved, but I'm not sure of the exact syntax. Thanks.