How To Connect My HTML Form On Database

Asked By 7060 points N/A Posted on -
qa-featured

He I need answer about Connection html registration Form into database system.

Is It possible or not ?

Pleased answer me i need fast answer.

SHARE
Best Answer by rapuyot
Answered By 0 points N/A #195082

How To Connect My HTML Form On Database

qa-featured

Its simple.

The hardest part is to connect the two. But even that easy. So first of you need your DB.

DB.PHP 
Make a new .php file with the following code inside. [replace the xxx with your info] 

$host="Localhost"; ///– Local host 
$db="XXX"; ///– db name 
$username="XXX"; ///– db username 
$password="XXX"; ///– db password 

The database name normally is root. And password is your servers admin password. 

Best Answer
Best Answer
Answered By 0 points N/A #82563

How To Connect My HTML Form On Database

qa-featured

Q: He I need answer about Connection html registration Form into database system. Is It possible or not ?

Please answer me I need fast answer.
 
Ans: Yes you can connect your html registration into a database system by creating a .php file. Here are the instructions:
 
1. Design your registration form using html, begin with the standard heading and include the form tag. Additionally, don't forget to include also  the attribute name  of every text/combobox/radiobutton/listbox. See sample below…
 
<html><head><title>Sample Reg</title></head><body>
 
<form method ="post" action="reg.php">
 
<label>Name:</label><input type="text" name="name" id="name' size ="50" maxlength="50"/> //text box for name
 
</form>
 
</body>
 
</html>
 
2. Create a database in your local computer or web server (ex. registration). Add new table with corresponding fields required in your form (ex. regtable with a  field named name). Add new user, set the username, password and add privileges (create, delete, add, alter). 
 
3. If you would notice the form tag in step 1, I used reg.php for action attribute. In this case, you are going to create a new reg.php file.
 
Begin with standard format of .php file using <?php and ends with ?>. 
 
First, you must create a connection to your database, mysql_connect function was used, inside that include parameters such as your server, username, password set to use the database.
 
Second, call the elements in your html form then assign that to a variable to store data temporarily.
 
Third, Select the database.
 
Fourth, Insert records to  the table
 
Lastly, check if the record was successfully stored in database.
 
See complete sample code below.
 
<?php
 
$link = mysql_connect("localhost", "rapuyot, "12345") or die ("Could not connect.:". mysql_error()); //rapuyot is the username, 12345 is the password.
 
$DB = "registration"; //registration is the database name
 
$table = "regtable"; //regtable is the table name
 
$name = $_POST["name"]; //["name"] -> name attribute of text box name in your html form.
 
mysql_select_db($DB) or die ("Database $DB not select…" .mysql_error()0;
 
$query = "INSERT INTO $table (Name, ……., ……. , ……..) VALUES ('$name', '$……', '$……', '$……')"; //name is the field in table named regtable.
 
if(! mysql_query ($query, $link)) die ("MySQL error…<p>" . mysql_error());
 
print"<p> Successfully data added to table: $table"; 
 
?>
 
4. Check your database if the records were successfully added into the table.

 

Login/Register to Answer

Related Questions