Posting HTML Form data to MySQL via PHP

This is a discussion on Posting HTML Form data to MySQL via PHP within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I just need a correct PHP statement that will allow me to instert a record into a MySQL database/table. ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-25-2004
Mark Johnson
 
Posts: n/a
Default Posting HTML Form data to MySQL via PHP

I just need a correct PHP statement that will allow me to instert a record
into a MySQL database/table. The "mysql_query(" statment used below does
not work.
----------------------------------------------------------------------------
$hostname="mysql5.secureserver.net";
$username="xxxxxxx";
$password="yyyyyy";
$dbname="zzzzzzzz";
$usertable="Visitors";
$verbindung = @mysql_connect($hostname, $username, $password)or die
("Failed");
mysql_select_db($dbname);

$firstname=$_POST['firstName'];
$lastname=$_POST['lastName'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zipcode=$_POST['zipCode'];
$country=$_POST['Country'];
$phone=$_POST['phone'];
$email=$_POST['eMail'];

mysql_query("INSERT INTO $usertable VALUES
'$firstname','$lastname','$address1','$address2',' $city','$state','$z
ipcode','$country','$phone','$email'");

mysql_close($verbindung);
echo "<br>Done...";
?>
----------------------------------------------------------------------------
-

--Mark


"Mark Johnson" <mdjohns5@comcast.net> wrote in message
news:4oKdnax6JMVsh-HcRVn-rA@comcast.com...
> I have a very straight forward FORM in a HTML page with 10 fields (name,
> address, phone, email, etc.)
>
> On the backend I have a MySQL database/table defined with the

corresponding
> fields.
> (FirstName, LastName,Address1,Address2,City,State,ZipCode,Coun try, Phone,
> Email)
>
> I need to know what PHP syntax to use to store the data caputred in the

FORM
> to to the MySQL database. (This is not rocket science, I am just a newbie

to
> MySQL/PHP.)
>
> Here is the syntax for my HTML form:
> ---------------------------------------
> <form action="scripts/mySQLTest.php" method="post" name="reg" id="reg">
>
> Here is the syntax for the PHP script: (UID/PWD changed to protect the
> innocent ;?)
> --------------------------------------------------------------------------

--
> ---------
> <?php
> //Database Connection Syntax for PHP and MySQL.
> //Connect To Database
>
> $hostname="mysql5.secureserver.net";
> $username="xxxxxxx";
> $password="yyyyyy";
> $dbname="zzzzzzzz";
> $usertable="Visitors";
>
> mysql_connect($hostname,$username, $password) OR DIE ("<html><script
> language='JavaScript'<alert('Unable to connect to database! Please try

again
> later.'),history.go(-1)</script></html>");
>
> mysql_select_db($dbname);
> ?????????????????????????????????????????????????? ???????????????
> echo "Done";
> ?>
> --------------------------------------------------------------------------

--
> -----------------
>
> I know the database is set up correctly because I have been able to

manually
> add records (via the Admin panel) and then write a PHP script to read that
> data and echo it out to a HTML page.
>
> I am using Macromedia Dreamweaver to create the HTML and PHP. When the

FORM
> is selecetd in Dreamweaver, I can choose to alter the following

properties:
> * Action (scripts/mySQLtest.php)
> * Method (default, GET or POST) ???
> * Enctype ("", application/x-www-form-urlencoded, or multipart/form-data)
> ???
>
> In addition to needing the PHP line to post to MySQL, I need some guidance
> on what to choose for the ablve "Method" and "Enctype" (or does it

matter).
>
> Thanks in advance!
>
> Mark
>
>




Reply With Quote
  #2 (permalink)  
Old 10-25-2004
Daedalus
 
Posts: n/a
Default Re: Posting HTML Form data to MySQL via PHP

> mysql_query("INSERT INTO $usertable VALUES
> '$firstname','$lastname','$address1','$address2',' $city','$state','$z
> ipcode','$country','$phone','$email'");


Missing ( ) around the values after VALUES
mysql_query("INSERT INTO $usertable VALUES
('$firstname','$lastname','$address1','$address2', '$city',
'$state','$zipcode','$country','$phone','$email')" );


Dae



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:42 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0