pTutorial

New way to learn PHP Example

PHP retrieve form Data from database

PHP retrieve form data into database

All the PHP, CSS and HTML code are below in different section and complete script can be downloaded from clicking the download button below shown.

Create form using html 5




<html>

<head>



</head>

<body>

<h2>Retrieve form data</h2>



</body>

</html>



This is a simple form using HTML 5 and nothing else you can create form your own way, it's not a big deal.

CSS code for Formatting


<style>

#uk

{

	color:#00F;

	font-size:36px;

	border:#00C 2px solid;

	width:200px;

	

	

	}

</style>

Little bit CSS for formatting the form, you can design form as you needed.

PHP script for store data on database


<?php

$a1=mysql_connect("localhost", "root", "")or die("connection fail");

$b=mysql_select_db("test", $a1) or die("can't select table");

 $data="select *from reg_form";

 $data1=mysql_query($data,$a1)or die(mysql_error());

echo "<table width='1000' border='1' >"."<tr>";



while($row = mysql_fetch_array($data1)) 

{

  

    echo "<td>".$row['f-n']."<br>"."</td>";

//  echo "<td>".$row['l-name']."<br>"."</td>";

//	echo "<td>".$row['dddoooz']."<br>"."</td>";

//	echo "<td>".$row['qualiii']."<br>"."</td>";

	echo "<td>".$row['ssmm']."<br>"."</td>";

	echo "<td>".$row['eee-id']."<br>"."</td>";

//	echo "<td>".$row['cc-no']."<br>"."</td>";

//	echo "<td>".$row['aaad']."<br>"."</td>";

	echo"</tr>";

 





}

   echo"</table>";

   echo "<br/>"; 

mysql_close($a1);

?>



Output

connection fail

Explanation

The mysql_fetch_array returns one row of data from the temporary table specified by $data1.

After this statement, $row is an array containing all the fields in the temporary table.

We are using a while loop to get one row at a time, processing each row until the end of the table is reached.

f-n, l-name, dddoooz, qualiii etc. are the field name of the table.

Note: Please use relevant name as field name like first-name, last-name etc.

If you want to learn more about PHP MySql visit previous section.


Before run this script please create database named test and import SQL file (test.sql) that are given in downloaded folder.

Download source code


QUOTES OF THE DAY

A single death is tragedy, a million death is a static.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER