If u need ajax for edit your display record. it display all record in table row column format that will save (edit) by sending data using ajax javascript function to server php file and get response from server of fail and success and intimate user about the server response.
//**************************************** Edit ajax file ****************************************
<?php
$dbc=mysql_connect('localhost','root','');
mysql_select_db('databasename',$dbc);
$do = $_REQUEST['do'];
$cateId = $_REQUEST['cateId'];
switch($do) {
case 'edit':
$newTitle=$_REQUEST['ptitle'];
$newDesc=$_REQUEST['pDesc'];
$photoId=$_REQUEST['Id'];
if(get_magic_quotes_gpc()) {
$photoId = $photoId;
$newTitle=$newTitle;
$newDesc=$newDesc;
}else{
$photoId = addslashes($photoId);
$newTitle = addslashes($newTitle);
$newDesc = addslashes($newDesc);
}
$updatPhoto="update photo_gallery set title='$newTitle',description='$newDesc' where id=$photoId";
if(mysql_query($updatPhoto,$dbc)or die('Error in update : '.mysql_error())){
header('Content-Type: text/xml');
header('Pragma: no-cache');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<result>';
echo 'true';
echo '</result>';
}else{
header('Content-Type: text/xml');
header('Pragma: no-cache');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<result>';
echo 'false';
echo '</result>';
}
break;
default:
echo 'Error, invalid action';
break;
}
?>
//***************************************AJax file end*************************************************
//*********************** Edit html File Start ***********************************************
<script type="text/javascript">
// *************************Ajax call function start***************************************
function editPhotoDetail(Id){
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
}else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
var handle = Id;
var url = 'ajax.php?';
//alert(handle);
var newtitle=document.getElementById('title'+handle).value;
var newDesc=document.getElementById('desc'+handle).value;
//alert('title : ' + newtitle+' '+photoId );
// alert('Desc : ' + newDesc);
if(handle > 0) {
//alert('call statechange');
var fullurl = url + 'do=edit&Id=' + encodeURIComponent(handle)+'&ptitle=' + encodeURIComponent(newtitle) + '&pDesc=' + encodeURIComponent(newDesc);
http.open("POST", fullurl, true);
http.send(null);
http.onreadystatechange = statechange_detailchange(handle);
}
}
function statechange_detailchange(handle) {
//alert('in statechange');
if (http.readyState == 4) {
var xmlObj = http.responseXML;
var rs = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
// alert('RS '+rs);
if(rs=="true"){
errorField = document.getElementById('msgbox'+handle);
errorField.innerHTML = "Photo Record Successfully Update";
errorField.style.visibility='visible';
errorField.style.border='#339900 solid 1px';
errorField.style.background='#FBE3E4';
errorField.style.color='#339900';
errorField.style.fontSize='12px';
}else{
errorField = document.getElementById('msgbox'+handle);
errorField.innerHTML = "Photo Record Update Fail.";
errorField.style.visibility='visible';
errorField.style.border='#FF3333 solid 1px';
errorField.style.background='#C9FFCA';
errorField.style.color='#8a1f11';
errorField.style.fontSize='12px';
}
}
}
//*********************************Ajax call function end*********************************
</script>
//********************************Record fetch from database and display for edit
<table>
<?php
$selRec="select * from table";
$rsRec=mysql_query($selRec,$dbc);
while($row=mysql_fetch_array($rsRec)){
?>
<tr>
<td><input type="radio" name="coverId" value="<?php echo $newId;?>" onclick="setId(<?php echo $newId;?>)"/></td>
<td height="170px" width="190px" valign="middle" align="center">
<span id="msgbox<?php echo $row["id"];?>"></span>
</td>
<td valign="top"><input type="text" size="30" name="title<?php echo $row["id"];?>" id="title<?php echo $row["id"];?>" value="<?php echo $row["title"];?>"></td>
<td valign="top"><textarea name="desc<?php echo $newId;?>" id="desc<?php echo $row["id"];?>" rows=7><?php echo $row["descs"];?></textarea> </td>
<td align="center"><a onclick="editDetail(<?php echo $row["id"];?>)"><span style="color:#003300; background-color:#C4FFE1; font-family:Arial, Helvetica, sans-serif; font-size:14px;">Edit</span></a></td>
</tr>
<?php
}?>
</table>
//*****************************Html file end***************************************
Saturday, December 12, 2009
Friday, December 11, 2009
Create Contact Us form for website
Create Contact us form where any request fill by any site visitor and all information will send to a site admin Email Id automatically by mail function.
<?php
$mailto = 'destination email id' ;
$formurl = "from email id" ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$subject = $_POST['thesubject'] ;
$message = $_POST['themessage'] ;
$name = $_POST['name'] ;
$address = $_POST['address'] ;
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$postalcode = $_POST['postalcode'] ;
$country = $_POST['country'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$phone1 = $_POST['phone1'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
$thankyouurl='thanx.php';//page where redirect after mail contact form successfully
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------- COMMENTS -------------------------\n\n" .
" Subjet : $thesubject\n\n Message : $themessage\n\n Name : $name\n Address : $address\n City :$city\n State : $state\n Postal Code: $postalcode\n\n Phone : $phone, $phone1\n Country : $country\n\n Email : $email\n";
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper, "From: \"$Name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit ;
?>
<form id="form1" method="post" action="mailSend.php">
<table border="0" cellspacing="5" style="width: 397px">
<tr>
<td colspan="2">
<h3>
Send a Enquiry</h3>
</td>
<tr>
<td style="padding-top: 10px" width="95">
</td>
<td style="padding-top: 10px" width="283">
<input type="hidden" id="ToEMail" name="ToEMail" value="contact@victoriamortgagebrokers.com.au" />
<input type="hidden" id="thanksPage" name="thanksPage" value="http://victoriamortgagebrokers.com.au/Thanks.html" />
</td>
<tr>
<td width="95">
Name
</td>
<td width="283">
<input type="text" id="txtName" name="txtName" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Contact No.
</td>
<td width="283">
<input type="text" id="txtPhone" name="txtPhone" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
e-mail ID
</td>
<td width="283">
<input type="text" id="txtEmail" name="txtEmail" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Suburb.
</td>
<td width="283">
<input type="text" id="txtsuburb" name="txtSuburb" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Post Code
</td>
<td width="283">
<input type="text" id="txtpostCode" name="txtPostCode" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Home Telephone</td>
<td width="283">
<input type="text" id="txtHomePhone" name="txtHomePhone" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Office Telephone</td>
<td width="283">
<input type="text" id="txtofficePhone" name="txtOfficePhone" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Mobile
</td>
<td width="283">
<input type="text" id="txtmobile" name="txtmobile" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Looking For</td>
<td width="283">
<input type="text" id="txtlookingfor" name="txtlookingfor" style="width: 283px" />
</td>
</tr>
<tr>
<td valign="top" width="95">
Comments
</td>
<td width="283">
<textarea id="txtComments" name="txtComments" style="width: 283px; height: 91px"></textarea>
</td>
</tr>
<tr>
<td width="95">
</td>
<td align="right" style="padding-right: 25px" width="259">
<input id="Button1" type="submit" value="Send" />
</td>
</tr>
</table>
</form>
<?php
$mailto = 'destination email id' ;
$formurl = "from email id" ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$subject = $_POST['thesubject'] ;
$message = $_POST['themessage'] ;
$name = $_POST['name'] ;
$address = $_POST['address'] ;
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$postalcode = $_POST['postalcode'] ;
$country = $_POST['country'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$phone1 = $_POST['phone1'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
$thankyouurl='thanx.php';//page where redirect after mail contact form successfully
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------- COMMENTS -------------------------\n\n" .
" Subjet : $thesubject\n\n Message : $themessage\n\n Name : $name\n Address : $address\n City :$city\n State : $state\n Postal Code: $postalcode\n\n Phone : $phone, $phone1\n Country : $country\n\n Email : $email\n";
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper, "From: \"$Name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit ;
?>
<form id="form1" method="post" action="mailSend.php">
<table border="0" cellspacing="5" style="width: 397px">
<tr>
<td colspan="2">
<h3>
Send a Enquiry</h3>
</td>
<tr>
<td style="padding-top: 10px" width="95">
</td>
<td style="padding-top: 10px" width="283">
<input type="hidden" id="ToEMail" name="ToEMail" value="contact@victoriamortgagebrokers.com.au" />
<input type="hidden" id="thanksPage" name="thanksPage" value="http://victoriamortgagebrokers.com.au/Thanks.html" />
</td>
<tr>
<td width="95">
Name
</td>
<td width="283">
<input type="text" id="txtName" name="txtName" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Contact No.
</td>
<td width="283">
<input type="text" id="txtPhone" name="txtPhone" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
e-mail ID
</td>
<td width="283">
<input type="text" id="txtEmail" name="txtEmail" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Suburb.
</td>
<td width="283">
<input type="text" id="txtsuburb" name="txtSuburb" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Post Code
</td>
<td width="283">
<input type="text" id="txtpostCode" name="txtPostCode" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Home Telephone</td>
<td width="283">
<input type="text" id="txtHomePhone" name="txtHomePhone" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Office Telephone</td>
<td width="283">
<input type="text" id="txtofficePhone" name="txtOfficePhone" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Mobile
</td>
<td width="283">
<input type="text" id="txtmobile" name="txtmobile" style="width: 283px" />
</td>
</tr>
<tr>
<td width="95">
Looking For</td>
<td width="283">
<input type="text" id="txtlookingfor" name="txtlookingfor" style="width: 283px" />
</td>
</tr>
<tr>
<td valign="top" width="95">
Comments
</td>
<td width="283">
<textarea id="txtComments" name="txtComments" style="width: 283px; height: 91px"></textarea>
</td>
</tr>
<tr>
<td width="95">
</td>
<td align="right" style="padding-right: 25px" width="259">
<input id="Button1" type="submit" value="Send" />
</td>
</tr>
</table>
</form>
Labels:
cantact us,
mail
Thursday, December 10, 2009
Get video duration without ffmpeg function
If we need to get video duration in php if server not support ffmepg function than use following code to get duration.
ob_start();
passthru("ffmpeg -i ".$videoName." 2>&1");
$duration = ob_get_contents();
ob_end_clean();
$search='/Duration: (.*?)[.]/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE);
$duration = $matches[1][0];
list($hours, $mins, $secs) = split('[:]', $duration);
echo "Hours: ".$hours." Minutes: ".$mins." Seconds: ".$secs;
$duration=$mins.':'.$secs;
ob_start();
passthru("ffmpeg -i ".$videoName." 2>&1");
$duration = ob_get_contents();
ob_end_clean();
$search='/Duration: (.*?)[.]/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE);
$duration = $matches[1][0];
list($hours, $mins, $secs) = split('[:]', $duration);
echo "Hours: ".$hours." Minutes: ".$mins." Seconds: ".$secs;
$duration=$mins.':'.$secs;
Labels:
video duration
Wednesday, December 9, 2009
Place multiple submit form on page
Fetch all record form image table and create form as per record on a single page. and submit form on button. With the following example code u can place multiple submit form on single page and submit single form according to button submit. display form with pagination.
This example will help in understand pagination in php.
<!--
Javascript Function for submit Form
-->
<script language="javascript">
function function1(theForm){
theForm.submit();
}
</script>
<?php
$dbc=mysql_connect('hostname','username','password');
mysql_select_db('databasename',$dbc);
$start=$_REQUEST['startPostion'];
$display=20;
if(isset($start)&&is_numeric($start)){
$startNo=trim($start);
}else{
$startNo=0;
}
/*
Get TotalNo of Images in images table for calculate the no of pages
*/
$selCount="select count(id) from images where status='Ok'";
$countRs=mysql_query($selCount,$dbc);
$count=mysql_fetch_row($countRs);
if($count[0]>$display){
$pages=ceil($count[0]/$display);
}else{
$pages=1;
}
if($pages>1){
$currentPage=($startNo/$display)+1;
$stPageNo=$currentPage-4;
$endPageNo=(($currentPage+5)<$pages)? $currentPage+5 : $pages;
if($currentPage!=1){
echo '<a href="imageManager.php?startPostion='.($startNo-$display).'"><span class="nextpre">Previous </span></a>';
}
for($i=$stPageNo;$i<=$endPageNo;$i++){
if($i>0){
if($i==$currentPage){
echo '<span class="currpagingNo">'.$i.' '.'</span>';
}else{
echo '<a href="imageManager.php?startPostion='.($display*($i-1)).'"><span class="pagingNo">'.$i.' '.'</span></a>';
}
}
} echo '<span class="nextpre">...of '.$pages.'</span>';
if($currentPage!=$pages){
echo '<a href="wallpaperManager.php?startPostion='.($startNo+$display).'"><span class="nextpre">Next</span></a>';
}
}
?>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="360" align="center"><span class="style1">Wallpaper Detail </span> </td>
<td width="72" align="center"><span class="style1">Added Date</span> </td>
<td align="center"><span class="style1">Action </span></td>
</tr>
<?php
$selImage="select * from images where status='Ok' limit $startNo,$display";
$imageResult=mysql_query($selImage,$dbc);
while($row=mysql_fetch_row($imageResult)){
?>
<tr>
<td height="150" valign="top" >
<table width="340" border="1" cellspacing="0" cellpadding="0">
<form id="form1" name="forms<?php echo $row[0]; ?>" method="post" action="imageManager.php">
<tr>
<td width="80"> <span class="style1">Title</span> </td>
<td width="254">
<input type="text" name="photo_title" size="50" value="<?php echo $row[1]; ?>"> <input type="hidden" name="ask" value="activate" >
</td>
</tr>
<tr>
<td width="80"> <span class="style1">Description</span> </td>
<td width="254">
<input type="text" name="photo_desi" size="50" value="<?php echo $row[2]; ?>"> <input type="hidden" name="ask" value="activate" >
</td>
</tr>
</form>
</table>
</td>
<td align="center"><span id="textstyle"><?php echo $row[3]; ?></span></td>
<td align="center" width="38" valign="middle"><img src="../../All Users/Documents/images/yes.png" border="0" title="Activate" onclick="function1(forms<?php echo $row[0]; ?>)"></a></td>
</tr>
<?php
}
?>
</table>
This example will help in understand pagination in php.
<!--
Javascript Function for submit Form
-->
<script language="javascript">
function function1(theForm){
theForm.submit();
}
</script>
<?php
$dbc=mysql_connect('hostname','username','password');
mysql_select_db('databasename',$dbc);
$start=$_REQUEST['startPostion'];
$display=20;
if(isset($start)&&is_numeric($start)){
$startNo=trim($start);
}else{
$startNo=0;
}
/*
Get TotalNo of Images in images table for calculate the no of pages
*/
$selCount="select count(id) from images where status='Ok'";
$countRs=mysql_query($selCount,$dbc);
$count=mysql_fetch_row($countRs);
if($count[0]>$display){
$pages=ceil($count[0]/$display);
}else{
$pages=1;
}
if($pages>1){
$currentPage=($startNo/$display)+1;
$stPageNo=$currentPage-4;
$endPageNo=(($currentPage+5)<$pages)? $currentPage+5 : $pages;
if($currentPage!=1){
echo '<a href="imageManager.php?startPostion='.($startNo-$display).'"><span class="nextpre">Previous </span></a>';
}
for($i=$stPageNo;$i<=$endPageNo;$i++){
if($i>0){
if($i==$currentPage){
echo '<span class="currpagingNo">'.$i.' '.'</span>';
}else{
echo '<a href="imageManager.php?startPostion='.($display*($i-1)).'"><span class="pagingNo">'.$i.' '.'</span></a>';
}
}
} echo '<span class="nextpre">...of '.$pages.'</span>';
if($currentPage!=$pages){
echo '<a href="wallpaperManager.php?startPostion='.($startNo+$display).'"><span class="nextpre">Next</span></a>';
}
}
?>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="360" align="center"><span class="style1">Wallpaper Detail </span> </td>
<td width="72" align="center"><span class="style1">Added Date</span> </td>
<td align="center"><span class="style1">Action </span></td>
</tr>
<?php
$selImage="select * from images where status='Ok' limit $startNo,$display";
$imageResult=mysql_query($selImage,$dbc);
while($row=mysql_fetch_row($imageResult)){
?>
<tr>
<td height="150" valign="top" >
<table width="340" border="1" cellspacing="0" cellpadding="0">
<form id="form1" name="forms<?php echo $row[0]; ?>" method="post" action="imageManager.php">
<tr>
<td width="80"> <span class="style1">Title</span> </td>
<td width="254">
<input type="text" name="photo_title" size="50" value="<?php echo $row[1]; ?>"> <input type="hidden" name="ask" value="activate" >
</td>
</tr>
<tr>
<td width="80"> <span class="style1">Description</span> </td>
<td width="254">
<input type="text" name="photo_desi" size="50" value="<?php echo $row[2]; ?>"> <input type="hidden" name="ask" value="activate" >
</td>
</tr>
</form>
</table>
</td>
<td align="center"><span id="textstyle"><?php echo $row[3]; ?></span></td>
<td align="center" width="38" valign="middle"><img src="../../All Users/Documents/images/yes.png" border="0" title="Activate" onclick="function1(forms<?php echo $row[0]; ?>)"></a></td>
</tr>
<?php
}
?>
</table>
Labels:
multiple form,
PHP,
submit form
Tuesday, December 8, 2009
Upload Email Refine it and save it to database
*
if($Id!=""){
$insertEmail="insert into emailgroup values($newgroupId,'$group','$Id','y',$count)";
if(mysql_query($insertEmail,$dbc)){
echo '<div class="success">Email Uploaded</div>';
}else{
echo '<div class="error">Email Uploaded Fail</div>';
}
}
if($wrongId!=""){echo '<div class="error">Wrong Email Id:-'.$wrongId.'</div>';}
}
?>
<body>
<center>
<table width="80%" border="1">
<tr>
<td colspan="2" align="center" ><img src="http://www.totalbhakti.com/wallpaper/images/logo.png" border="0"></td>
</tr>
<tr>
<td width="20%" valign="middle">
<?php include('left.php');?>
</td>
<td>
<fieldset>
<legend>Email Id Upload Panel</legend>
<form name="emailform" action="emailUpload.php" method="post">
<table width="95%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td width="30%"><strong>Select Email Group</strong></td>
<td >
<select name="group" id="group" onchange="selectionShow(document.getElementById('group'),'New',document.getElementById('newGroup1'))" >
<option>General</option>
<?php
$selectGroup="select group_name from emailgroup group by group_name";
$result=mysql_query($selectGroup,$dbc) or die('error in group:-'.mysql_error());
while($row=mysql_fetch_row($result)){
echo'<option>'.$row[0].'</option>';
}
?>
<option>New</option>
</select>
</td>
</tr>
<tr id="newGroup1" style="visibility:hidden">
<td align="right">
<strong>Enter New Group</strong>
</td>
<td>
<input type="text" name="newGroup" id="newGroup" >
</td>
</tr>
<tr >
<td colspan="2" id="errorGroup" style="visibility:hidden">
</td>
</tr>
<tr>
<td align="left">
<strong>Enter Email Id's</strong>
</td>
<td>
<textarea name="emailId" id="emailId" cols="40" rows="10" ></textarea>
</td>
</tr>
<tr >
<td colspan="2" id="errorId" style="visibility:hidden">
</td>
</tr>
<tr >
<td align="right">
<input type="hidden" name="act" value="true" />
</td>
<td>
<input type="button" value="Upload" onclick="onSubmited(emailform)" >
</td>
</tr>
</table>
</form>
</fieldset>
</td>
</tr>
</table>
This post will help in copy all email id and pase it to textarea and click on upload button. Programme will automatically filter all invalid id and organize them and create group or add to exit group as u want.
<?php
$dbc=mysql_connect('localhost','userName','password');
$dbc=mysql_connect('localhost','userName','password');
mysql_select_db('database name',$dbc);
function gethtmlformat($txt){ //Function for RIght syntex for html format
$txt=str_replace('%0D%0A','',$txt);
$txt=str_replace('+','',$txt);
$txt=str_replace(',%20',',',$txt);
return($txt);
}
$action=$_REQUEST['act'];
$newGroup=$_REQUEST['newGroup'];
//echo $newGroup;
$oldGroup=$_REQUEST['group'];
$emailId=urlencode($_REQUEST['emailId']); //replace space with +
$emailId=urldecode(gethtmlformat($emailId));
//echo $emailId;
$EmailArray=explode(",",$emailId); //Create array of uploaded email string
$totemail=count($EmailArray); //Count total email in arrary
//echo $totemail;
$count=0;
$Id;
$wrongId;
$group;
if(isset($action)){
if($newGroup!="" ){
$group=$newGroup;
}else{
$group=$oldGroup;
}
//echo $group.'<br>';
function chkEmail($email){
//echo $email;
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ // function will validate email id
return("Invalid");
}else{
return("Valid");
}
}
for($i=0;$i<$totemail;$i++){
//echo $i;
if(isset($EmailArray[$i])){
//echo $EmailArray[$i].'<br>';
if(chkEmail($EmailArray[$i])=="Valid"){
$Id.=$EmailArray[$i].',';
$count+=1;
//echo $Id.'<br>';
}elseif(chkEmail($EmailArray[$i])=="Invalid"){
$wrongId.=$EmailArray[$i].'<br>';
//echo $wrongId.'<br>';
}
}
//echo chkEmail($EmailArray[$i]);
}
//echo $Id;
//****************************start Get New ID for News letter to send*****************
$selMaxId="select max(id) from emailgroup";
$result=mysql_query($selMaxId,$dbc)or die('Error in Fetch Id'.mysql_error());
$rs=mysql_fetch_row($result);
$groupId=$rs[0];
$newgroupId=$groupId+1;
//*******************************End get New ID for Greeting ********************
//******************************Check Group Exit or not************
function chkGroup($value,$dbc){
$chk="select group_name,emailid from emailgroup where group_name='$value'";
$chkRs=mysql_query($chk,$dbc) or die('error in group:-'.mysql_error());
$value1=mysql_fetch_row($chkRs);
//echo $value.$value1[1].'<br>';
return($value1[1]);
}
//*************************************************function gethtmlformat($txt){ //Function for RIght syntex for html format
$txt=str_replace('%0D%0A','',$txt);
$txt=str_replace('+','',$txt);
$txt=str_replace(',%20',',',$txt);
return($txt);
}
$action=$_REQUEST['act'];
$newGroup=$_REQUEST['newGroup'];
//echo $newGroup;
$oldGroup=$_REQUEST['group'];
$emailId=urlencode($_REQUEST['emailId']); //replace space with +
$emailId=urldecode(gethtmlformat($emailId));
//echo $emailId;
$EmailArray=explode(",",$emailId); //Create array of uploaded email string
$totemail=count($EmailArray); //Count total email in arrary
//echo $totemail;
$count=0;
$Id;
$wrongId;
$group;
if(isset($action)){
if($newGroup!="" ){
$group=$newGroup;
}else{
$group=$oldGroup;
}
//echo $group.'<br>';
function chkEmail($email){
//echo $email;
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ // function will validate email id
return("Invalid");
}else{
return("Valid");
}
}
for($i=0;$i<$totemail;$i++){
//echo $i;
if(isset($EmailArray[$i])){
//echo $EmailArray[$i].'<br>';
if(chkEmail($EmailArray[$i])=="Valid"){
$Id.=$EmailArray[$i].',';
$count+=1;
//echo $Id.'<br>';
}elseif(chkEmail($EmailArray[$i])=="Invalid"){
$wrongId.=$EmailArray[$i].'<br>';
//echo $wrongId.'<br>';
}
}
//echo chkEmail($EmailArray[$i]);
}
//echo $Id;
//****************************start Get New ID for News letter to send*****************
$selMaxId="select max(id) from emailgroup";
$result=mysql_query($selMaxId,$dbc)or die('Error in Fetch Id'.mysql_error());
$rs=mysql_fetch_row($result);
$groupId=$rs[0];
$newgroupId=$groupId+1;
//*******************************End get New ID for Greeting ********************
//******************************Check Group Exit or not************
function chkGroup($value,$dbc){
$chk="select group_name,emailid from emailgroup where group_name='$value'";
$chkRs=mysql_query($chk,$dbc) or die('error in group:-'.mysql_error());
$value1=mysql_fetch_row($chkRs);
//echo $value.$value1[1].'<br>';
return($value1[1]);
}
if($Id!=""){
$insertEmail="insert into emailgroup values($newgroupId,'$group','$Id','y',$count)";
if(mysql_query($insertEmail,$dbc)){
echo '<div class="success">Email Uploaded</div>';
}else{
echo '<div class="error">Email Uploaded Fail</div>';
}
}
if($wrongId!=""){echo '<div class="error">Wrong Email Id:-'.$wrongId.'</div>';}
}
?>
<body>
<center>
<table width="80%" border="1">
<tr>
<td colspan="2" align="center" ><img src="http://www.totalbhakti.com/wallpaper/images/logo.png" border="0"></td>
</tr>
<tr>
<td width="20%" valign="middle">
<?php include('left.php');?>
</td>
<td>
<fieldset>
<legend>Email Id Upload Panel</legend>
<form name="emailform" action="emailUpload.php" method="post">
<table width="95%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td width="30%"><strong>Select Email Group</strong></td>
<td >
<select name="group" id="group" onchange="selectionShow(document.getElementById('group'),'New',document.getElementById('newGroup1'))" >
<option>General</option>
<?php
$selectGroup="select group_name from emailgroup group by group_name";
$result=mysql_query($selectGroup,$dbc) or die('error in group:-'.mysql_error());
while($row=mysql_fetch_row($result)){
echo'<option>'.$row[0].'</option>';
}
?>
<option>New</option>
</select>
</td>
</tr>
<tr id="newGroup1" style="visibility:hidden">
<td align="right">
<strong>Enter New Group</strong>
</td>
<td>
<input type="text" name="newGroup" id="newGroup" >
</td>
</tr>
<tr >
<td colspan="2" id="errorGroup" style="visibility:hidden">
</td>
</tr>
<tr>
<td align="left">
<strong>Enter Email Id's</strong>
</td>
<td>
<textarea name="emailId" id="emailId" cols="40" rows="10" ></textarea>
</td>
</tr>
<tr >
<td colspan="2" id="errorId" style="visibility:hidden">
</td>
</tr>
<tr >
<td align="right">
<input type="hidden" name="act" value="true" />
</td>
<td>
<input type="button" value="Upload" onclick="onSubmited(emailform)" >
</td>
</tr>
</table>
</form>
</fieldset>
</td>
</tr>
</table>
Labels:
email upload,
email validation in php,
group
Friday, December 4, 2009
Add/Remove dynamic rows in HTML table
Add or remove row or item form html table dynamically.
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
cell1.innerHTML = "Select Photo : ";
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "file";
cell3.appendChild(element2);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD>Select File : </TD>
<TD> 1 </TD>
<TD> <INPUT type="file" name="file" /> </TD>
</TR>
</TABLE>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
cell1.innerHTML = "Select Photo : ";
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "file";
cell3.appendChild(element2);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD>Select File : </TD>
<TD> 1 </TD>
<TD> <INPUT type="file" name="file" /> </TD>
</TR>
</TABLE>
Labels:
daynamic,
javascript,
table
Wednesday, December 2, 2009
Url rewriting rule for .htaccess
Their are some rule that should be follow when we use url rewriting. Their are solution with example and definition of all parameter and tell how to use them in url rewriting.
Rewrite rules are broken down into 4 simple blocks.
This one little piece of the mod rewrite is where the power is. In the pattern block of the rewrite rule we use regular expressions to detect the requested file name or uri and from this we can extract key parts to pass to the rewrite block.
Pattern Matching metacharacter Definitions
Class Definitions []
Example:-
RewriteRule ^category/([0-9]+)\.htm$ /category.php?cat_id=$1 [L]
The best to use is the negated class since .+ will pick up a / since a / is defined as any given character. The [-a-zA-Z0-9]+ would just take up too much computing power over the long run. Remember the more you define the more strain there is on the system. Since a search for every thing but a / ([^/]+) requires less computing power it's not only fast it most optimal.
Remember a reference is anything that was picked up in the () in the rewrite.
To call a reference you just add a $ follow by the reference number. This all goes in order like so. Below we'll make 3 references.
RewriteRule ^dir/(.*)/(.*)\.(.htm|.html)$ /$1/$2.$3 [R=301,L]
Rewrites using a 301 redirect
dir/some/folder/file.htm to /some/folder/file.htm
You can mix up the references if you want like so:
RewriteRule ^dir/(.*)/(.*)\.(.htm|.html)$ /$2/$1.$3 [R=301,L]
you can also not call a reference like so:
RewriteRule ^dir/(.*)/(.*)\.(.htm|.html)$ /$2/$1.php [R=301,L]
Command Flag Block (Optional)
Ok I didn't tell you this is optional because half of you would skip this part. Learning the different Command Flags is a must.
The command flag definitions are as follows:
EAJBJZSSMQEB
Rewrite rules are broken down into 4 simple blocks.
- Call to action
- Pattern
- Rewrite
- Command Flag.
Example
RewriteRule ^dir/([0-9]+)/?$ /index.php?id=$1 [L]
Call to action: RewriteRule
Pattern: ^dir/([0-9]+) /?$
Rewrite: /index.php?id=$1
Command Flag: [L]
Pattern: ^dir/([0-9]+) /?$
Rewrite: /index.php?id=$1
Command Flag: [L]
Call to action Block
if you ever see a 500 error on your site it mostlikely due to a bad line of code in your .htaccess file. The only way to screw this up is to spell RewriteRule incorrectly or leave out the space between this and the starting of the pattern block.
Pattern Block
Pattern Matching metacharacter Definitions
| Char. | Definition |
| \ | Use before any of the following characters to escape or null the meaning or it. \* \. \$ \+ \[ \] |
| ^ | Start matching at this point |
| $ | End point of the match |
| . | Any character |
| [] | Starts a class |
| | | Starts alternative match this|that would mean match this or that |
| () | starts a back reference point |
| ? | match 0 or 1 time Quantifier |
| + | match atleast 1 or more times Quantifier |
| * | match 0 to infinite times Quantifier |
| {} | match minimum to maximum Quantifier {0,3} match up to 3 times |
| Char. | Definition |
| ^ | Negates the class. [^A-Z]+ means don't match any uppercases |
| \ | Use before any of the following characters to escape or null the meaning or it. [\+]+ |
| - | Range for matching [0-9]+ [a-zA-Z]+ |
RewriteRule ^category/([0-9]+)\.htm$ /category.php?cat_id=$1 [L]
The best to use is the negated class since .+ will pick up a / since a / is defined as any given character. The [-a-zA-Z0-9]+ would just take up too much computing power over the long run. Remember the more you define the more strain there is on the system. Since a search for every thing but a / ([^/]+) requires less computing power it's not only fast it most optimal.
Rewrite Block
This part is a piece of cake. Now that we've used the pattern block to reference our matches ([0-9]+) we need to rewrite to the url and add the references as needed.Remember a reference is anything that was picked up in the () in the rewrite.
To call a reference you just add a $ follow by the reference number. This all goes in order like so. Below we'll make 3 references.
RewriteRule ^dir/(.*)/(.*)\.(.htm|.html)$ /$1/$2.$3 [R=301,L]
Rewrites using a 301 redirect
dir/some/folder/file.htm to /some/folder/file.htm
You can mix up the references if you want like so:
RewriteRule ^dir/(.*)/(.*)\.(.htm|.html)$ /$2/$1.$3 [R=301,L]
you can also not call a reference like so:
RewriteRule ^dir/(.*)/(.*)\.(.htm|.html)$ /$2/$1.php [R=301,L]
Command Flag Block (Optional)
Ok I didn't tell you this is optional because half of you would skip this part. Learning the different Command Flags is a must.
The command flag definitions are as follows:
| Char. | Definition |
| [R] | Redirect you can add an =301 or =302 to change the type. |
| [F] | Forces the url to be forbidden. 403 header |
| [G] | Forces the url to be gone 401 header |
| [L] | Last rule. (You should use this on all your rules that don't link together) |
| [N] | Next round. Rerun the rules again from the start |
| [C] | Chains a rewrite rule together with the next rule. |
| [T] | use T=MIME-type to force the file to be a mime type |
| [NS] | Use if no sub request is requested |
| [NC] | Makes the rule case INsensitive |
| [QSA] | Query String Append use to add to an existing query string |
| [NE] | Turns of normal escapes that are default in the rewriterule |
| [PT] | Pass through to the handler (together with mod alias) |
| [S] | Skip the next rule S=3 skips the next 3 rules |
| [E] | E=var sets an enviromental variable that can be called by other rules |
Labels:
htaccess,
url rewirting
Subscribe to:
Posts (Atom)