Jump to content


Photo

Form PHP Post Database


  • Please log in to reply
No replies to this topic

#1 Nik_Castronova

Nik_Castronova
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 18 May 2004 - 07:57 PM

To whom it may concern:

What I think I Need: CODE (PHP/HTML/?) that will send information from a form created in Dreamweaver using HTML to a databse set up on a yahoo webhosting account using MySQL.

Reason: www.reneepatrice.com needs to be able to collect data from visitors to her website so that she may then mail out to them updates and special offers.

I do not know PHP, I know HTML. I created a form, with all propper elements, including a button to 'send info'.... don't know what tags or coding to use to link that button to a MySQL databse that HAS BEEN created through a yahoo web hosting account.

I feel like the solution to this problem must be simple, but I am not finding the information I need! - DONT KNOW WHERE TO LOOK.

If actual code is too much to ask for, can someone please refer me in the right direction as to where I can learn how to properly link these two elements together... I have a book on PHP, on Dreamweaver, on HTML and I have one with all of them together.... I must be retarted I still can't figure it out.

-nik

you may e-mail me at: nik_c@usa.com

here is the form page:
http://www.reneepatr...MailingList.htm
[/CODE]
<TD width=429 rowSpan=8 valign="top" bgColor=#000000><p><FONT FACE=ARIAL size=-1><img src="buttons/mailname.png" width="77" height="18">
<font color="#FFFFFF">
<input name="firstname" type="text" value="" size="10" maxlength="20">
</font> </FONT><FONT FACE=ARIAL size=-1><font color="#FFFFFF">
<input name="lastname" type="text" value="" size="25" maxlength="30">
</font></FONT></p>
<p> <font color="#FFFFFF"> <img src="buttons/mailemail.png" width="77" height="18">
<input name="email" type="text" size="45" maxlength="50">
</font><font color="#FFFFFF"> </font><FONT FACE=ARIAL size=-1> <font color="#FFFFFF">
</font> </FONT><FONT FACE=ARIAL size=-1><font color="#FFFFFF"> </font></FONT><FONT FACE=ARIAL size=-1></FONT></p>
<p><font color="#FFFFFF"><img src="buttons/mailaddress.png" width="77" height="18">
<input name="address" type="text" size="45" maxlength="50">
</font><FONT FACE=ARIAL size=-1> <font color="#FFFFFF"> </font> </FONT><FONT FACE=ARIAL size=-1><font color="#FFFFFF">
</font></FONT><FONT FACE=ARIAL size=-1></FONT></p>
<p><font color="#FFFFFF"><img src="buttons/mailcity.png" width="77" height="18">
<input name="city" type="text" size="40" maxlength="30">
</font><font color="#FFFFFF"> </font><FONT FACE=ARIAL size=-1> <font color="#FFFFFF">
</font> </FONT><FONT FACE=ARIAL size=-1><font color="#FFFFFF"> </font></FONT><FONT FACE=ARIAL size=-1></FONT><font color="#FFFFFF">
</font><FONT FACE=ARIAL size=-1> <font color="#FFFFFF"> </font> </FONT><FONT FACE=ARIAL size=-1><font color="#FFFFFF">
</font></FONT><FONT FACE=ARIAL size=-1></FONT></p>
<p><font color="#FFFFFF"><img src="buttons/mailstate.png" width="77" height="18">
<input name="state" type="text" size="2" maxlength="2">
</font><font color="#FFFFFF"> </font><FONT FACE=ARIAL size=-1> <font color="#FFFFFF">
</font> </FONT><FONT FACE=ARIAL size=-1><font color="#FFFFFF"> </font></FONT><font color="#FFFFFF"><img src="buttons/mailzip.png" width="31" height="18">
<input name="zip" type="text" size="5" maxlength="5">
</font></p>
<p><font color="#FFFFFF"><img src="buttons/mailphone.png" width="77" height="18">
<input name="areacode" type="text" size="3" maxlength="3">
</font><font color="#FF0099">-</font><font color="#FFFFFF">
<input name="phone1" type="text" size="3" maxlength="3">
</font><font color="#FF0099">-</font><font color="#FFFFFF">
<input name="phone2" type="text" size="4" maxlength="4">
<img src="images/UniqueHandDesBlackSpace.jpg" width="70" height="21">
<a href="home.htm"><img src="buttons/sendinfo.jpg" border="0"></a> </font></p>
</TD>
</TR>


--------------------

nik castronova, graphic design (1996-2004)
nik_c@usa.com


NaGahl Posted: May 18 2004, 12:26 AM


n00bie


Group: Members
Posts: 6
Member No.: 11,424
Joined: 16-May 04



Nik:

your form on your html page should look something like this, yes?:

<form action="filename.php" method="post">

...some stuff here

<input type="submit" value="Submit">
</form>

when you click on submit, your browser gathers up everything in the form and fires it off to the webserver. The webserver gets it and hands it off to the file shown in the first line:

...action="filename.php"...

the .php file takes all the data (stored in an array as global variables) and sticks it into the mySQL database. Of course, you have to tell the script what data you want and where you want to stick it or else it just goes away (like socks in the washer).

suppose you have a section of your form for your illustrious user to give you an email address:

<input type="text" length="100" maxlength="100" name="email">

the key here is:

...name="email"...

this is a...handle...if you will, which PHP can use to get at the contents of that field.

meanwhile back at the script....

$email = $_POST['email'];

this line creates a variable called $email and assigns a value to it. The value is taken from the array created to hold the data sent by the form from the previous page. In this case we are going to end up with the contents of the form field named email. Which should be the email address. Other variables are created in exactly the same way, such as:

$name = $_POST['your_name'];
$address = $_POST['home']'
$hatsize = $_POST['hatsize'];

As long as 'your_name', 'home' and 'hatsize' exist in your form, the data contained will be stored as variables (technically, they're all variables, but shortening them makes it easier to work with).

Now you need a connection to mySQL:

$db = mysql_connect('<hostname>', '<username>','<password>');

...and pick a database to use....

mysql_select_db('<databasename>');

Now you need a query. the query is constructed just as if you were using mySQL without a browser or script. it's generally easier/cleaner to create a variable for your query. Like this:

$query = "insert into <table> values ('$email', '$name', '$hatsize')";

and then query mySQL with it, like this:

$result = mysql_query($query);

mySQL is going to return some information, which I have assigned to the variable $result. This way I can work with it some more, if I need to.

That's about it. Of course, there are security issues with what can be passed into the script, what's stored in mySQL, etc. but that's the general idea.

-NaGahl

Nik_Castronova Posted: May 18 2004, 12:37 PM


n00bie


Group: Members
Posts: 2
Member No.: 11,467
Joined: 17-May 04



Here is the site:

http://www.reneepatr.....lb=85217122")

with the form.

Here is what comes up on the yahoo web server SQL when I enter new info (manually through yahoo MySql):

SQL-query : [Edit] [Create PHP Code]
UPDATE `MailingList` SET `CustomerID` = '0000000003',
`Name` = 'Mickey',
`Name2` = 'Mouse',
`Email` = 'BigRat@disney.com',
`Address` = 'Cindarella\'s Castle, Apt 12',
`City` = 'Walt Disney',
`State` = 'FL',
`Zip` = '12345',
`Phone1` = '123',
`Phone2` = '456',
`Phone3` = '1234' WHERE `CustomerID` = '' AND `Name` = '' AND `Name2` = '' AND `Email` = '' AND `Address` = '' AND `City` = '' AND `State` = '' AND `Zip` = '' AND `Phone1` = '' AND `Phone2` = '' AND `Phone3` = '' LIMIT 1 ;


I think I need to go through the yahoo web server's php administrator to apply any data to the databases.

I know email is the table... the 'Name', 'Name2', etc.. are the fields. The entries for these fields (above) equate to one of the rows (defined by customer ID #).

I AM SO LOST!


--------------------

nik castronova, graphic design (1996-2004)
nik_c@usa.com






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users