|
Posted by Jerim79 on 11/07/06 22:27
I am no PHP programmer. At my current job I made it known that I was no
PHP programmer during the interview. Still they have given me a script
to write with the understanding that it will take me a while (This
information is just for general knowledge as I don't want anyone
thinking I am trying to be dishonest with my intentions. Also, I do not
portray myself as something I am not. I am a beginner.)
Anyway, what the script needs to do is to take variables passed from an
HTML form and do two things. One is read it into a database. The other
is to send me an email with all of the customer's information.
//Name of the script is test.php
<?php
//I am using this echo command to make sure that the variables where
passed correctly.
echo $_Post['FName']; //Never displays
//Here is where the script for the database connections starts
$username='username';
$password='password';
$hostname='localhost';
$databasename='database';
//Here is where the database connection is actually made
$conection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to
database");
//With the database connection open, I start to insert the data from
the HTML form.
$result = mysql_query("INSERT INTO table() VALUES($FName,
$LName, $Company, $Title, $Address, $Apt, $City, $State, $Zip, $Phone,
$Fax, $Email, $Var1, $Var2, $Var3, $Var4, $Var5)");
//After reading the information into the table, we close the database
connection
mysql_close();
//This is where the email script starts (Both the database and email
scripts are inside the same php tags)
$mail_to="email address";
$mail_subject = "Review Registration";
$mail_body = "First Name: $_Post[FName]";
$mail_body .= "Last Name: $_Post[LName]" ;
$mail_body .= "Company: $_Post[Company]" ;
$mail_body .= "Title: $_Post[Title]" ;
$mail_body .= "Street: $_Post[Address]" ;
$mail_body .= "Apt: $_Post[Apt]" ;
$mail_body .= "City: $_Post[City]" ;
$mail_body .= "Zip: $_Post[Zip]" ;
$mail_body .= "Phone: $_Post[Phone]" ;
$mail_body .= "Fax: $_Post[Fax]" ;
$mail_body .= "Email: $_Post[Email]" ;
$mail_body .= "Var1: $_Post[Var1]" ;
$mail_body .= "Var2: $_Post[Var2]" ;
$mail_body .= "Var3: $_Post[Var3]" ;
$mail_body .= "Var4: $_Post[Var4]" ;
$mail_body .= "Var5: $_Post[Var5]" ;
//This if statement lets me know if the email went or not.
if(mail($mail_to, $mail_subject, $mail_body))
echo "Email was successfully sent";
else echo "Email was not sent!\n";
//I used this early on to show if the script executed. Later on I will
convert it to an if statement.
echo "Registration was successful!\n\n\n";
?>
A manual check on the database, shows me that no information was
entered. However, I can not determine if a connection was made and the
database was opened. I know the email works. However, for both the
email and the first echo statement at the top, no data is ever
displayed. None of the variables show up. It is as if the data is not
getting passed. In the HTML form I have:
<form method="post" action="test.php">
<input name="FName" type=text />
<input name="LName" type=text />
<input name="Company" type=text />
<input name="Title" type=text />
and so on..........
</form>
Thanks to some help from other posters I learned of the
$_POST['Variable'] method. That worked in a test case, but doesn't seem
to be working here. Not even the top echo statement will work like
that, as I have tried it both ways. I have been reading up, but most of
the information available isn't on point. For instance, am I inserting
the variables correctly into the table? I understand the difference
between local and passed variables. I am wondering if a statement at
the beginning such as $FName=$_POST['FName'] would take the passed
variable and store it locally. Any help will be greatly appreciated.
Navigation:
[Reply to this message]
|