Saturday, May 25, 2013
how to save and execute PHP program
1. use notepad for execute the code
2. in notepad
<html>
<head>
<title> PHP Page</title>
</head>
<body>
<from action="test.php" metho ="POST">
Please enter your name:<br />
I am....
<?php echo("<input type="text" name="person" value=" ' . $person . ' " size="15" />");
?>
<input type="submit" value="test!" size="30"/ >
</form>
</body>
</html>
3. save the example.php in Test folder
4. once the file is saved go to the browser and execute the file
How to run PHP in XAMPP
Using XAMPP is very easy. Follow these steps -
1. Run the XAMPP application. Turn on Apache & MySQL (if your application needs database) services through it.
2. find the folder where xampp is installed example C:\xampp\htdocs
3. create a folder in C:\xampp\htdocs example Test
4. in Test folder save PHP file example test.php
5. once the php file saved in test folder open browser any browser ex. firefox, internet explorer , google chrome etc.
6 . once the browser is opened type the following in address bar http://localhost/Test/test.php
your browser will execute the php file and we will find the webpage ...
1. Run the XAMPP application. Turn on Apache & MySQL (if your application needs database) services through it.
2. find the folder where xampp is installed example C:\xampp\htdocs
3. create a folder in C:\xampp\htdocs example Test
4. in Test folder save PHP file example test.php
5. once the php file saved in test folder open browser any browser ex. firefox, internet explorer , google chrome etc.
6 . once the browser is opened type the following in address bar http://localhost/Test/test.php
your browser will execute the php file and we will find the webpage ...
Thursday, May 23, 2013
Image upload to MYSQL database using PHP part II
<?php
include_once('db.php');
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM image WHERE id=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
echo $image;
?>
include_once('db.php');
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM image WHERE id=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
echo $image;
?>
Image upload to MYSQL database using PHP part I
<form action="index.php" method="POST" enctype="multipart/form-data">
File :
<input type="file" name="image" />
<input type="submit" value="Upload" />
</form>
<?php
include_once('db.php');
$file = $_FILES['image']['tmp_name'];
if(!isset($file))
echo"Please select an Image.";
else
{
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['tmp_name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "that's not an image.";
else
{
if(!$insert = mysql_query("INSERT INTO image VALUES('','$image_name','$image') "))
echo"Problem on uploading image.";
else
{
$lastid = mysql_insert_id();
echo "Image Uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
}
}
}
?>
Table name : image
fields : id, name, image
File :
<input type="file" name="image" />
<input type="submit" value="Upload" />
</form>
<?php
include_once('db.php');
$file = $_FILES['image']['tmp_name'];
if(!isset($file))
echo"Please select an Image.";
else
{
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['tmp_name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "that's not an image.";
else
{
if(!$insert = mysql_query("INSERT INTO image VALUES('','$image_name','$image') "))
echo"Problem on uploading image.";
else
{
$lastid = mysql_insert_id();
echo "Image Uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
}
}
}
?>
Table name : image
fields : id, name, image
Wednesday, May 22, 2013
Simple Registration form in HTML with JAVASCRIPT validation PART -II
<script>
function formValidation()
{
var userid = document.registration.userid;
var pass = document.registration.pass;
var uname = document.registration.username;
var uadd = document.registration.address;
var ucountry = document.registration.country;
var uzip = document.registration.zip;
var uemail = document.registration.email;
var umsex = document.registration.msex;
var ufsex = document.registration.fsex; if(userid_validation(userid,5,12))
{
if(pass_validation(pass,7,12))
{
if(allLetter(uname))
{
if(alphanumeric(uadd))
{
if(countryselect(ucountry))
{
if(allnumeric(uzip))
{
if(ValidateEmail(uemail))
{
if(validsex(umsex,ufsex))
{
}
}
}
}
}
}
}
}
return false;
}
function userid_validation(userid,mx,my)
{
var userid_len = userid.value.length;
if (userid_len == 0 || userid_len >= my || userid_len < mx)
{
alert("User Id should not be empty / length be between "+mx+" to "+my);
userid.focus();
return false;
}
return true;
}
function pass_validation(pass,mx,my)
{
var pass_len = pass.value.length;
if (pass_len == 0 ||pass_len >= my || pass_len < mx)
{
alert("Password should not be empty / length be between "+mx+" to "+my);
pass.focus();
return false;
}
return true;
}
function allLetter(uname)
{
var letters = /^[A-Za-z]+$/;
if(uname.value.match(letters))
{
return true;
}
else
{
alert('Username must have alphabet characters only');
uname.focus();
return false;
}
}
function alphanumeric(uadd)
{
var letters = /^[A-Za-z]+$/;
if(uadd.value.match(letters))
{
return true;
}
else
{
alert('User address must have alphabet characters only');
uadd.focus();
return false;
}
}
function countryselect(ucountry)
{
if(ucountry.value == "Default")
{
alert('Select your country from the list');
ucountry.focus();
return false;
}
else
{
return true;
}
}
function allnumeric(uzip)
{
var numbers = /^[0-9]+$/;
if(uzip.value.match(numbers))
{
return true;
}
else
{
alert('ZIP code must have numeric characters only');
uzip.focus();
return false;
}
}
function ValidateEmail(uemail)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(uemail.value.match(mailformat))
{
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
}
function validsex(umsex,ufsex)
{
x=0;
if(umsex.checked)
{
x++;
}
if(ufsex.checked)
{
x++;
}
if(x==0)
{
alert('Select Male/Female');
umsex.focus();
return false;
}
else
{
alert('Form Succesfully Submitted');
window.location.reload()
return true;
}
}
</script>
Simple Registration form in HTML with JAVASCRIPT validation PART -I
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<title>Registration form with javascript validation</title>
<link rel='stylesheet' href='js-form-validation.css' type='text/css' />
</head>
<body onload="document.registration.userid.focus();">
<h1>REGISTRATION</h1>
<div style="width: 500px; height: 570px; background-color: #fce729">
<form name='registration' onSubmit="return formValidation();">
<div>User id:</div>
<div><input type="text" name="userid" size="12" /></div>
<div>Password:</div>
<div><input type="password" name="pass" size="12" /></div>
<div>Name:</div>
<div><input type="text" name="username" size="50" /></div>
<div>Address:</div>
<div><input type="text" name="address" size="50" /></div>
<div>Country:</div>
<div><select name="country">
<option selected="" value="Default">(Please select a country)</option>
<option value="AF">Australia</option>
<option value="AL">Canada</option>
<option value="DZ">India</option>
<option value="AS">Russia</option>
<option value="AD">USA</option>
</select>
</div>
<div>ZIP Code:</div>
<div><input type="text" name="zip" /></div>
<div>Email:</div>
<div><input type="text" name="email" size="50" /></div>
<div>Sex:</div>
<div>
<input type="radio" name="sex" value="Male" /><span>Male</span>
<input type="radio" name="sex" value="Female" /><span>Female</span>
</div>
<div>Language:</div>
<div>
<input type="checkbox" name="en" value="en" checked /><span>English</span>
<input type="checkbox" name="nonen" value="noen" /><span>Non English</span>
</div>
<div>About:</div>
<div><textarea name="desc" id="desc"></textarea></div>
<div><input type="submit" name="submit" value="Submit" /></div>
</form>
</div>
</body>
</html>
Tuesday, May 21, 2013
Simple Captcha in PHP with javascript Validation
<html>
<head>
<title>Captcha validation </title>
<script>
function validateForm()
{
var val = document.forms ["myForm"]["captcha"].value;
if(val == null || val =="")
{
alert ("Please enter the Captcha on Text Box");
return false ;
}
}
</script>
</head>
<body>
<form name="myForm" action="validate.php" method="POST" onSubmit="return validateForm()">
Enter Image Text
<input name="captcha" type="text">
<img src="captcha.php" /><br>
<input name="submit" type="submit" value="Captcha Validation">
</form>
</body>
</html>
captcha.php
<?php
session_start();
$code=rand(1000,9999);
$_SESSION["code"]=$code;
$img = imagecreatetruecolor(50, 24);
$bgnd = imagecolorallocate($img, 22, 86, 165);
$fgnd = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $bgnd);
imagestring($img, 5, 5, 5, $code, $fgnd);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
validate.php
<?php
session_start();
if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
{
echo "Correct Code Entered";
//Do you stuff
}
else
{
die("Wrong Code Entered");
}
?>
Simple Selection Combo box MYSQL database and PHP
combobox.php
<?php
include_once('db.php');
?>
<div style="width:50px;height: auto; float: left; "> States:</div>
<div align="left" style="width:210px;height: auto; float: left; ">
<select name="states" onChange="getCities(this.value)">
<?php
$result = mysql_query("SELECT * FROM states");
while($row=mysql_fetch_array($result))
{
echo "<option value=".$row[id].">$row[states]</option>";
}
?>
</select>
</div>
database :
table name : states
table id : id
table Name : states
states
----------------------------
id | states
1 | Andra
2 | Tamil Nadu
3 | Pondicherry
db.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "test";
$mysql_password = "BJx3p2awbuTvdVwS";
$mysql_database = "test";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>
Monday, May 20, 2013
PHP code to connect MYSQL database
<?php
$hostname = "localhost";
$user = "user";
$password = "BJx3p2awbuTvdVwS";
$database = "test";
$prefix = "";
$bd = mysql_connect($hostname, $user, $password) or die("Could not connect database");
mysql_select_db($database, $bd) or die("Could not select database");
?>
Inserting From to date to the database using datepicker PHP MYSQL Part II
//qyuery to insert into database
<?php
include_once('db.php');
$datefrom = $_POST["datefrom"];
$dateto = $_POST["dateto"];
$sql = mysql_query("INSERT INTO date_avenue (date_from, date_to)VALUES('$datefrom','$dateto')");
?>
Inserting From to date to the database using datepicker PHP MYSQL Part I
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
function validate()
{
var x=document.forms["submitDate"]["datefrom"].value;
if (x==null || x=="")
{
alert("Click Date From");
return false;
}
var y=document.forms["submitDate"]["dateto"].value;
if (y==null || y=="")
{
alert("Click Date To");
return false;
}
}
$(document).ready(function() {
// For simple datepicker
// get the current date
var date = new Date();
var d = date.getDate(), m = date.getMonth(), y = date.getFullYear();
// Disable all dates till today
$('#datepicker1').datepicker({
minDate: new Date(y, m, d),
dateFormat: 'dd-mm-yy',
});
// Disable all dates till today
$('#datepicker2').datepicker({
minDate: new Date(y, m, d),
dateFormat: 'dd-mm-yy',
});
});
// pass datepicker to php
</script>
</head>
<body style="font-size:62.5%;">
<div class="dateTypes">
<form action="testquery.php" name="submitDate" id="submitDate" onsubmit="return validate()" method="post">
<div style="width:150px;height: 15px; float: left; font-size:12px; ">Date From </div>
<div>
<input type="text" name="datefrom" id="datepicker1" value="" />
</div>
<div style="width:150px;height: 15px; float: left; font-size:12px; ">Date To </div>
<div>
<input type="text" name="dateto" id="datepicker2" value="" />
</div>
<input type="submit" id="submitMe" value="Submit" OnClick="validate()">
</form>
</div>
</body>
</html>
Join Query in PHP retrieving date from database MYSQL Time From another Table - Part II
<?php
include_once('db.php');
$date = $_POST['date'];
$res = mysql_query("select time.id,time.date_id, time.time from time inner join date on date.date_id = time.date_id WHERE date.date ='$date' ");
?>
<select name="show_place" >
<option>Select</option>
<?php
while($row = mysql_fetch_array($res))
{
echo "<option value = ".$row[id]."> $row[time]</option>";
}
?>
</select>
Join Query in PHP retrieving date from database MYSQL Time From another Table I
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
function validate()
{
var x=document.forms["submitDate"]["date"].value;
if (x==null || x=="")
{
alert("Click Date From");
return false;
}
}
$(document).ready(function() {
// For simple datepicker
// get the current date
var date = new Date();
var d = date.getDate(), m = date.getMonth(), y = date.getFullYear();
// Disable all dates till today
$('#datepicker1').datepicker({
minDate: new Date(y, m, d),
dateFormat: 'dd-mm-yy',
});
});
// pass datepicker to php
</script>
</head>
<body >
<div class="dateTypes">
<form action="time1.php" name="submitDate" id="submitDate" onsubmit="return validate()" method="POST">
<div style="width:150px;height: 15px; float: left; font-size:12px; ">Date </div>
<div>
<input type="text" name="date" id="datepicker1" value="" />
</div>
<input type="submit" id="submitMe" value="Submit" OnClick="validate()">
</form>
</div>
</body>
</html>
Dependent combo box drop-down in PHP MYSQL JQUERY Part III
<?php
include_once('db.php');
$showId=intval($_GET['show_name']);
// $query="SELECT * FROM state ";
$query="SELECT * FROM show_place WHERE show_id='$showId'";
$result=mysql_query($query);
?>
<select name="show_place" onchange="getShowDate(<?php echo $showId ?>,this.value)">
<option>Select</option>
<?php
while($row=mysql_fetch_array($result))
{
echo"<option value= ".$row[show_placeid].">$row[show_place]</option>";
}
?>
</select>
Dependent combo box drop-down in PHP MYSQL JQUERY Part II
<?php
include_once('db.php');
?>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript">
function getXMLHTTP()
{ //fuction to return the xml http object
var xmlhttp=false;
try
{
xmlhttp=new XMLHttpRequest();
}
catch(e)
{
try
{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getShowPlace(showId)
{
var strURL="showplace.php?show_name="+showId;
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
document.getElementById('showplacediv').innerHTML=req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getTime(showId)
{
var strURL="time.php?date="+showId;
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
document.getElementById('timediv').innerHTML=req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
//date picker function
$(document).ready(function()
{
// Enable a range of dates
var enabledDaysRange = [["5-3-2013 to 5-31-2013", "6-1-2013 to 6-15-2013" ], '5-9-2013'];
function enableRangeOfDays(d)
{
for(var i = 0; i < enabledDaysRange.length; i++)
{
if($.isArray(enabledDaysRange[i]))
{
for(var j = 0; j < enabledDaysRange[i].length; j++)
{
var r = enabledDaysRange[i][j].split(" to ");
r[0] = r[0].split("-");
r[1] = r[1].split("-");
if(new Date(r[0][2], (r[0][0]-1), r[0][1]) <= d && d <= new Date(r[1][2], (r[1][0]-1), r[1][1]))
{
return [true];
}
}
}
else
{
if(((d.getMonth()+1) + '-' + d.getDate() + '-' + d.getFullYear()) == enabledDaysRange[i])
{
return [true];
}
}
}
return [false];
}
$('#datepicker8').datepicker(
{
dateFormat: 'dd-mm-yy',
minDate:0,
numberOfMonths: 2,
beforeShowDay: enableRangeOfDays
});
});
</script>
</head>
<body>
<div style="width:300px;height: auto; float: left; ">
<form method="post" action="ticketbooking.php" name="form1">
<div style="width:300px;height: 15px; float: left; "> </div>
<div style="width:100px;height: auto; float: left; "> Show Name :</div>
<div align="left" style="width:200px;height: auto; float: left; ">
<select name="show_name" onChange="getShowPlace(this.value)">
<?php
$result = mysql_query("SELECT * FROM show_name");
while($row=mysql_fetch_array($result))
{
echo "<option value=".$row[show_id].">$row[show_name]</option>";
}
?>
</select>
</div>
<div style="width:300px;height: 10px; float: left; "> </div>
<div style="width:100px;height: auto; float: left; "> Show Place : </div>
<div align="left" style="width:200px;height: auto; float: left; ">
<div id="showplacediv">
<select name="show_place" >
<option>----</option>
</select>
</div>
</div>
<div style="width:300px;height: 10px; float: left; "> </div>
<div style="width:100px;height: auto; float: left; "> Show Date : </div>
<div style="width:145px;height: auto; float: left; ">
<input type="text" name="date" id="datepicker8" onchange="getTime(this.value)" />
</div>
<div style="width:300px;height: 10px; float: left; "> </div>
<div style="width:100px;height: auto; float: left; "> Show Time : </div>
<div style="width:200px;height: auto; float: left; ">
<div id="timediv">
<select name="time" >
<option>----</option>
</select>
</div
</div>
<div style="width:300px;height: 10px; float: left; "> </div>
<div style="width:100px;height: auto; float: left; "> Catagory : </div>
<div align="left" style="width:200px;height: auto; float: left; ">
<input type="radio" name="catagory" value="Platinum">Platinum Rs.200/-<br>
<input type="radio" name="catagory" value="Gold">Gold Rs.150/-<br>
<input type="radio" name="catagory" value="Silver">Silver Rs.100/-
</div>
<div style="width:300px;height: 10px; float: left; "> </div>
<div style="width:100px;height: auto; float: left; "> Select Seats : </div>
<div align="left" style="width:200px;height: auto; float: left; ">
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div style="width:300px;height: 15px; float: left; "> </div>
<div align="center" style="width:300px;height: 30px; float: left; ">
<input type="submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
Dependent combo box drop-down in PHP MYSQL JQUERY Part I
PHP file name db.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "username";
$mysql_password = "BJx3p2awbuTvdVwS";
$mysql_database = "test";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>
Subscribe to:
Posts (Atom)