Two ways to connect MySQL via PHP (2)
Last Update:2017-02-28
Source: Internet
Author: User
The MySQL example shows my article in "Program and Code" in this website and the following routines:
Foreground HTML
< form enctype= "Multipart/form-data" action= "hb_ggzd.php" method= "POST" >
< tr >
< TD width= "251" >< small > You can take some time to fill in the form, or you can use electricity
Sub-mail contact,< a href= "mailto:likai333@21cn.com" >likai333@21cn.com</a >. </small ></td >
</tr >
< tr >
< TD valign= "top" width= "251" height= "to" >< small > Your name:</small ></td >
< TD width= "462" height= ">< small >< input name=" name "size=" "> </small ></td >
</tr >
< tr >
< TD valign= "top" width= "251" height= ">< small > your email:</small ></td >
< TD width= "462" height= ">< small >< input name=" Usermail "size=" Notoginseng "></small ></td >
</tr >
< tr >
< TD valign= "top" width= "251" height= ">< small > you want to advertise Web address:</small ></td >
< TD width= "462" height= "a" >< small >< small >< input name= "Userurl" size= "Notoginseng" value= "http://" > </small ></small ></td >
</tr >
< tr >
< TD valign= "top" width= "251" height= ">< small > you want to advertise website name:</small ></td >
< TD width= "462" height= ">< small >< input name=" sitename "size=" "></small ></td >
</tr >
< tr >
< TD valign= "top" width= "251" height= ">< small > Your company name:</small ></td >
< TD width= "462" height= ">< small >< input name=" Company "size=" Notoginseng "></small ></td >
</tr >
< tr >
< TD valign= "top" width= "251" height= ">< Small > Your tel:</small ></td >
< TD width= "462" height= ">< small >< input name=" phone "size=" "></small ></td >
</tr >
< tr >
Background php
< PHP
$DBH = mysql_connect (' localhost:3306 ', ' root ', ');
mysql_select_db (' Hbweb ');
$query = "INSERT into usemsg (Name,usermail,userurl,sitename, Company,phone) VALUES (' $name ', ' $usermail ', ' $userurl ', ' $ SiteName ', ' $company ', ' $phone ', ' $C 1 ', ' $C 2 ', ' $C 3 ', ' $C 4 ', ' $C 5 ');
$res = mysql_query ($query, $DBH);
$err = Mysql_error ();
if ($err) {
echo "Error occurred, please notify < a href=mailto:likai333@21cn.com > I </a >";
echo "$err";
}
Else
{echo "successfully warehousing";}
? >
Table structure:
CREATE TABLE usemsg (
Name varchar (255) NOT NULL default "Notname",
Usermail varchar (255) NOT NULL default "Notusermail",
Userurl varchar (255) NOT NULL default "Notuserurl",
SiteName varchar (255) NOT NULL default "Notsitename",
Company varchar (255) is not null default "Notcompany",
Phone varchar (255) NOT NULL default "Notphone",
);