How to Make ID Card Using PHP Mysql and HTML

In this article, you will learn How to Make an ID Card Using PHP Mysql and HTML. This project is a web-based system. In this Project having some files

How to Make an ID Card Using PHP Mysql and HTML Files:-

  • index.php
  • view.php
  • id.php
  • print.php
  • upload.php

index.php

<?php 
mysql_connect('localhost','root','');
mysql_select_db('id_card');

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/form.css"/>
</head>
<body>
  <div class="wrapper">
  <div class="header">
  <ul>
  <li><a href="index.php">Entry</a></li>
  <li><a href="view.php">View</a></li>
  <li><a href="print.php">Print</a></li>
  </ul>
  </div>
    <div class="inner_wrapper">
      <form method="POST" action="upload.php" enctype="multipart/form-data">
        <div class="row1">
	      <h1>Form</h1>
	    </div>
	  <div class="row2">
		<div class="name1">
	    <h2>Name</h2>
		</div>
		<div class="name2">
	    <input type="text" name="name" placeholder="Name" />
		</div>
	  </div>
	  <div class="row3">
		<div class="qual1">
	      <h2>Qualification</h2>
		</div>
		<div class="qual2">
	      <select name="qualification" required="true"/>
		  <option selected="true" disabled="true">Highest Qualification</option>
		  <option value="MCA">MCA</option>
		  <option value="MBA">MBA</option>
		  <option value="M.A.">M.A.</option>
		  <option value="M.Com">M.Com</option>
		  <option value="B.Com">B.Com</option>
		  <option value="BA">BA</option>
		  <option value="BCA">BCA</option>
		  <option value="BBA">BBA</option>
		  <option value="DCA">DCA</option>
		  <option value="+2">+2</option>
	  	  <option value="10th">10th</option>
		  </select>
		</div>
	  </div>
	  <div class="row4">
		<div class="com1">
	    <h2>Company Name</h2>
		</div>
		<div class="com2">
	    <input type="text" name="company" placeholder="Company Name"/>
		</div>
	  </div>
	  <div class="row5">
		<div class="des1">
	    <h2>Designation</h2>
		</div>
		<div class="des2">
	    <input type="text" name="designation" placeholder="Designation"/>
		</div>
	  </div>
	  <div class="row6">
	  	<div class="img1">
	    <h2>Image</h2>
		</div>
		<div class="img2">
	    <input type="file" name="file" />
		</div>
	  </div>
	  <div class="row7">
	    <input type="submit" name="submit"/>
		<input type="reset" name="Reset"/>
	  </div>
	  </form>
	</div>
  </div>
</body>
</html>

 

view.php

<?php mysql_connect('localhost','root','');
mysql_select_db('id_card');
?>
<html>
<head><title>Report</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<style>
table,tr,th,td{
border:1px solid;
border-collapse:collapse;
}
.print{
text-align:center;
margin:20px;
float:left;
}
button{
border-radius:5px;
cursor:pointer;
width:50px;
height:25px;
}
table{
    float: left;
    margin-left: -380px;
	margin-top:20px;
}
</style>
</head>
<body>
  <div class="header">
  <ul>
  <li><a href="index.php">Entry</a></li>
  <li><a href="view.php">View</a></li>
  <li><a href="print.php">Print</a></li>
  </ul>
  </div>
  
 <table>
 <tr>
 <th>Id</th>
 <th>Name</th>
 <th>Qualification</th>
 <th>Company Name</th>
 <th>Designation</th>
 <th>Image</th>
 <th>View</th>
 </tr>
 <?php 
 $query="select * from form ";
 $query1=mysql_query($query);
 while($result=mysql_fetch_array($query1)) { 
 ?>
 <tr>
 <td><?php echo $result['id'];?></td>
 <td><?php echo $result['name'];?></td>
 <td><?php echo $result['qualification'];?></td>
 <td><?php echo $result['company_name'];?></td>
 <td><?php echo $result['designation'];?></td>
 <td><?php echo $result['file'];?></td>
 <td><a href="id.php?id=<?php echo $result['id'];?>">View</a></td>
 </tr>
 <?php } ?>
 </table>
 <div class="print">
 <a href="print.php"><button>Print</button></a>
 </div>
</body>
</html>

id.php

<?php mysql_connect('localhost','root','');
mysql_select_db('id_card');
$id=$_GET['id'];
?>
<html>
<head><title>ID Card</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
  <div class="wrapper">
    <div class="header">
  <ul>
  <li><a href="index.php">Entry</a></li>
  <li><a href="view.php">View</a></li>
  <li><a href="print.php">Print</a></li>
  </ul>
  </div>
    <div class="inner_wrapper">
	  <div class="col1">
	  	<?php
		$query="select * from form where id='$id'";
		$query1=mysql_query($query);
		while($result=mysql_fetch_array($query1)) { ?>
	    <img src="image/<?php echo $result['file']; ?>" />
	  </div>
	  <div class="col2">
	    <ul>
		  <li>Name</li>
		  <li>Qualification</li>
		  <li>Company Name</li>
		  <li>Designation</li> 
		</ul>
	  </div>
	  <div class="col3">
	    <ul>
		  <li>:</li>
		  <li>:</li>
		  <li>:</li>
		  <li>:</li>
		</ul>
	  </div>
	  <div class="col4">
	    <ul>
	
		  <li><?php echo $result['name']; ?></li>
		  <li><?php echo $result['qualification']; ?></li>
		  <li><?php echo $result['company_name']; ?></li>
		  <li><?php echo $result['designation']; ?></li>
		
		 <?php } ?>
		</ul>
	  </div>
	</div>
	<div class="back">
	  <a href="index.php"><button>Back to Index</button></a>
	</div>
  </div>
</body>
</html>

print.php

<?php mysql_connect('localhost','root','');
mysql_select_db('id_card');
?>
<html>
<head><title>ID Card</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<style>
.inner_wrapper{
margin:20px;
}
</style>
</head>
<body>
  <div class="wrapper">
    <div class="header">
  <ul>
  <li><a href="index.php">Entry</a></li>
  <li><a href="view.php">View</a></li>
  <li><a href="print.php">Print</a></li>
  </ul>
  </div><br><br>
    <?php
	$query="select * from form ";
	$query1=mysql_query($query);
	while($result=mysql_fetch_array($query1)) { ?>
      <div class="inner_wrapper">
	    <div class="col1">
	      <img src="image/<?php echo $result['file']; ?>" />
	    </div>
	  <div class="col2">
	    <ul>
		  <li>Name</li>
		  <li>Qualification</li>
		  <li>Company Name</li>
		  <li>Designation</li> 
		</ul>
	  </div>
	  <div class="col3">
	    <ul>
		  <li>:</li>
		  <li>:</li>
		  <li>:</li>
		  <li>:</li>
		</ul>
	  </div>
	  <div class="col4">
	    <ul class="info">
		  <li><?php echo $result['name']; ?></li>
		  <li><?php echo $result['qualification']; ?></li>
		  <li><?php echo $result['company_name']; ?></li>
		  <li><?php echo $result['designation']; ?></li>
		</ul>
	  </div>
	</div>
    <?php } ?>
    <div class="back">
	  <a href="index.php"><button>Back to Index</button></a>
    </div>
  </div>
</body>
</html>

upload.php

<?php
mysql_connect('localhost','root','');
mysql_select_db('id_card');
if(isset($_POST['submit'])=='submit')
{    
    $name=$_POST['name'];
	$qual=$_POST['qualification'];
	$com=$_POST['company'];
	$desg=$_POST['designation'];
	$file = rand(1000,100000)."-".$_FILES['file']['name'];
    $file_loc = $_FILES['file']['tmp_name'];
	$file_size = $_FILES['file']['size'];
	$file_type = $_FILES['file']['type'];
	$folder="image/";
	
	// new file size in KB
	$new_size = $file_size/1024;  
	// new file size in KB
	
	// make file name in lower case
	$new_file_name = strtolower($file);
	// make file name in lower case
	
	$final_file=str_replace(' ','-',$new_file_name);
	
	if(move_uploaded_file($file_loc,$folder.$final_file))
	{
		$sql="INSERT INTO form(name,qualification,company_name,designation,file,type,size) VALUES('$name','$qual','$com','$desg','$final_file','$file_type','$new_size')";
		mysql_query($sql);
		?>
		<script>
		alert('successfully uploaded');
        window.location.href='view.php?success';
        </script>
		<?php
	}
	else
	{
		?>
		<script>
		alert('error while uploading file');
        window.location.href='index.php?fail';
        </script>
		<?php
	}
}
?>

 

The zip file is given below for the source code you just have to download and use it easily. The second major task is to host on a web server.
There are many web hosting available but hosting servers with user-friendly nature is here for you people where there are the best top 10 web hosting companies listed for you, Top 10 Web Hosting Companies that provide quality hosting within the relevant budget as a variety of memberships are available so it becomes easy for people like us to get a budget-friendly web hosting. Moreover, the code above is in the most commonly used languages i.e. PHP and HTML so the complexity of coding is not a big issue here. Just the basic software’s are required which need to be downloaded on the computers to make the code run smoothly without any error. 

Download the Source Code

1 thought on “How to Make ID Card Using PHP Mysql and HTML”

Leave a Comment