You are here: Re: Database/Email Script « PHP Programming Language « IT news, forums, messages
Re: Database/Email Script

Posted by Jerim79 on 11/08/06 15:48

Jerim79 wrote:
> Carl wrote:
> > Jerim79 wrote:
> > > 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();
> > >8 Message Cut >8
> >
> > Hi Jerim,
> >
> > A couple of things;
> > - $_Post is not the same as $_POST.
> > - When a function returns a value (as is the case with mysql_query()),
> > It is usually wise to check the value returned and make sure it is what
> > you expected.
> > - The mysql_error() function (http://php.net/mysql_error) is quite
> > useful when debugging these sorts of problems.
> >
> > Hope that helps,
> > Carl.
>
> I tried out POST instead of Post. I even set the method to POST. It
> still won't even display the top echo $_POST['FName'] so I don't think
> the variables are getting passed.
>
> However, I had a question about the mail script. I keep getting this
> error:
> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> expecting T_STRING or T_VARIABLE or T_NUM_STRING in /(website)/test.php
> on line 270
>
> Line 270 is this:
> $message = "First Name: $_POST['FName']";
>
> I believe the problem is the way in which I am adding the variable
> $_POST['FName] to the line. I saw this method used somewhere: "First
> Name: \"$_POST['FName']\""; but it didn't seem to work for me. I
> haven't been able to find anything on point.

I was able to figure out the POST issue. If you use " in the name on
the HTML form, you have to use " in the PHP script. So $_POST['FName']
didn't work but $_POST["FName"] does. (I haven't seen this mentioned
anywhere.)

The other issue I am having, besides the email issue is the database
INSERT. Here is the code:
$result = mysql_query("INSERT INTO table() VALUES($FName, $LName,
$Company, $Title, $Address, $Apt, $City, $State, $Zip, $Phone, $Fax,
$Email, $Var1, $Var2, $Var3, $Var4, $Var5)")

I know that $FName isn't the proper way to do it. However, when I set
it to $_POST["FName"] I get this error:

Parse error: syntax error, unexpected '"', expecting T_STRING or
T_VARIABLE or T_NUM_STRING in /website/test.php on line 264

I did insert this command to show any database errors, but it doesn't
show any:
echo mysql_error($connection)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация