Gadgets

Monday, 29 December 2014

HTML Login form with validation



HTML Login form with validation
In this article I explained that, HTML Login form with client side validation. Here in this form I taken email id and password, in this form we should give the correct email id pattern otherwise it will not take wrong email id pattern and here I taken password pattern, that password should be  a-z,A-Z,0-9 and password length is between 8 to 30 letters.



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="" method="post">
<table align="center">
<tr><td>Email id :</td><td><input type="email"name="eid" pattern="^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$" tabindex="1"required /></td></tr>
<tr><td>Password :</td><td><input type="password"name="psw" tabindex="2" pattern="[a-zA-Z0-9 ]{8,30}"required/></td></tr>
<tr><td></td><td><input type="submit" value="SignIn"tabindex="3"/></td></tr>
</table>
</form>
</body>
</html>
Email id :
Password :

Get the check box values from database in php


Get the check box values from database in php

This program teaches you how to get the multiple checkbox values, dropdown select option values and radio button values from database using PHP. By using this program we can get the values into HTML Form from Database. This article is easy to understand and I hope it will help you.



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
include “database_connection.php”;
$sql= mysql_query("select * from studentinfo where studentname”narendar”");
$row = mysql_fetch_array($sql);
$sname=$row[“studentname”];
$fname=$row[“fathername”];
$gender=$row[“gender”];
$sub  = explode(“,”,$row[“subjects”]);
$country=$row[“country”];
?>
<form action=""method="post">
<h3 align="center">Edit Information</h3>
<table border="1" cellpadding="2" cellspacing="2" align="center"><tr>
<td>Student Name :</td><td><input type="text" name="sname" value="<?echo $sname;?>"></td></tr>
<tr><td>Father Name:</td><td><input type="text" name="fname" value="<?echo $fname;?>"></td></tr>
<tr><td>Gender:</td><td><input type="radio" name="gender" value="male"
<?php echo ($gender==”male”)?"checked":"" ;?>>Male &nbsp;
<input type="radio" name="gender" value="female"
<?php echo ($gender==”female”)?"checked":"" ;?>>Female</td></tr>
<tr><td>Subjects:</td><td>
<?
if(in_array("maths",$sub))
echo “<input type="checkbox" name="subjects[]" value="maths" checked>Maths <br>”;
else
echo “<input type="checkbox" name="subjects[]" value="maths">Maths <br>”;
if(in_array("science",$sub))
echo “<input type="checkbox" name="subjects[]" value="science"checked>Science <br>”;
else
echo “<input type="checkbox" name="subjects[]" value="science">Science <br>”;
if(in_array("computers",$sub))
echo “<input type="checkbox" name="subjects[]" value="computers"checked>Computers <br>”;
else
echo “<input type="checkbox" name="subjects[]" value="computers">Computers <br>”;
if(in_array("english",$sub))
echo “<input type="checkbox" name="subjects[]" value="english"checked>English “;
else
echo “<input type="checkbox" name="subjects[]" value="english">English”;
?>
</td></tr>
<tr>
<td>Country:</td>
<td>
<select name="country">
<option disabled selected><?echo $country;?></option>
<option  >----select----</option>
<option>India</option>
<option>Japan</option>
<option>USA</option>
</select>
</td>
</tr>
<tr><td></td>
<td><input type="submit" name="submit" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>

Friday, 19 December 2014

Insert Checkbox Values into MySQL Using PHP



Insert Checkbox Values into MySQL Using PHP

This article teaches you how to insert HTML form multiple checkbox values,dropdown select option values and radio button values into MySQL database using PHP. This article is easy to understand and I hope it will help you. 
<html>
<head>
<title>Student Registration</title>
</head>
<body>
<?php
include "database_connection.php";
if(isset($_POST["submit"])){
$sname  =   $_POST["sname"];
$fname  =   $_POST["fname"];
$gender =   $_POST["gender"];
$subjects    =   implode(",",$_POST["subjects"]);
$country    =   $_POST["country"];
$sql    =   "INSERT INTO  `studentinfo`(`studentname`,`fathername`,`gender`,`subjects`,`country`)
values("$sname","$fname","$gender","$subjects","$country")";
$query  =   mysql_query($sql) or die(mysql_error());
if
($query){
echo "<h1>Data inserted successful.....</h1>";
}else{
echo "<h1>Please Try again.....</h1>";
}
}
?>
<form name="registration" method="post" action="">
<table border="1" cellpadding="2" cellspacing="2" align="center">
<tr>
<td>Student Name :</td><td><input type="text" name="sname" required=""></td>
</tr>
<tr>
<td>Father Name:</td><td><input type="text" name="fname" required=""></td>
</tr>
<tr>
<td>Gender:</td><td><input type="radio" name="gender" value="male" required="">Male &nbsp;
<input type="radio" name="gender" value="female" >Female</td></tr>
<tr>
<td>Subjects:</td><td><input type="checkbox" name="subjects[]" value="maths">Maths &nbsp;<br>
<input type="checkbox" name="subjects[]" value="science">Science &nbsp; <br>
<input type="checkbox" name="subjects[]" value="computers">Computers &nbsp; <br>
<input type="checkbox" name="subjects[]" value="english">English &nbsp;</td></tr>
<tr><td>Country:</td>
<td><select name="country">
<option >----select----</option>
<option>India</option>
<option>Japan</option>
<option>USA</option>
</select></td></tr>
<tr><td></td>
<td><input type="submit" name="submit" value="Register"></td>
</tr>
</table>
</form>
</body>
</html>






Get the check box values from database in php

 



Friday, 28 November 2014

Create new database in mysql



Create new database in mysql:

After installed “phpmyadmin”
Open link  http://localhost/phpmyadmin  in any browser
In home page you will get an option i.e, “create new database”




In that text box type your database name and then click on “create”
Here I taken “university” is my database name





now your database created, add privileges to your database.
click on “privileges”


click on “add new user”


type your username and password as I showed in figure
click on “check all” and click on “go”



now you added privileges to your database
create a table in your database
you get option that “create new table on database”
type table name and number of fields
click on “go”


fill the field as I showed in figure and I taken that “student _id” is “primary key”
and click on “save”


now your table is created in your database
if you want add one more field to same table, you have a option that below table
I showed in figure
Click on “go” and add field to the same table


Now one more field added to your table