How to Know How many row update in
mysql.
Ans:- Mysql_affected_rows();
Insert created current id in to
another table in Mysql.
Ans: - mysql_insert_id()
How to change date formate
Ans:- $currentDateFrom=date('Y-m-d',strtotime($currentDate)-24*60*60);
How to fetch data in random from
database?
Ans:-
$query="SELECT * FROM product
ORDER BY RAND( )LIMIT 0 , 5 ";
$result=mysql_query($query);
=========
conn.php
==========
$db=mysql_connect('localhost','root','');
mysql_select_db('userinfo',$db);
?>
======================
HOW TO INSERT
======================
include('conn.php');
if(isset($_POST['submit']))
{
/* if($_FILES['image']['name'])
{
$pname='images/'.$_FILES['image']['name'];
$source=$_FILES['image']['tmp_name'];
copy($source,$pname);
}
*/
if($_FILES['image']['name'])
{
$target='images/'.$_FILES['image']['name'];
$source=$_FILES['image']['tmp_name'];
copy($source,$target);
}
$query="insert into name of table
set Name='".$_POST['name']."',Title='".$_POST['title']."',Descripation='".$_POST['description']."',image='$pname'";
mysql_query($query) or
die(mysql_error());
} ?>
=================
FORM METHOD
=================
form close always end of body
=================
FETCH
=================
$query="select * from name of
table";
$result=mysql_query($query) or
die(mysql_error());
while($row=mysql_fetch_object($result))
{
?>
ID; ?>
Name; ?>
Title; ?>
Descripation;
?>
}
?>
=========================
SPECIAL CONDITION
=========================
$i=1;
while($row=mysql_fetch_object($result))
{
?>
$querya="select * from catagory
where id='$row->Catagory'";
$resulta=mysql_query($querya) or die
(mysql_error());
$rowa=mysql_fetch_object($resulta);
?>
name; ?>
$queryc="select * from
subcatagory where id='$row->Subcatagory'";
$resultc=mysql_query($queryc) or die
(mysql_error());
$rowc=mysql_fetch_object($resultc);
?>
name; ?>
name; ?>
price; ?>
sku; ?>
description;
?>
date; ?>
$i++;
}
?>
==============
EDIT
==============
From data select other table
...........................................
$queryg="select * from
category";
$resultg=mysql_query($queryg) or die
(mysql_error());
?>
Category:-
--Select
Catagory--
while($rowg=mysql_fetch_object($resultg))
{
?>
Category==$rowg->ID) {echo
'selected=selected';} ?>>Name;?>
}
?>
$queryc="select * from
subcategory";
$resultc=mysql_query($queryc) or die
(mysql_error());
?>
Subcategory:-
--Select
Subcategory
while($rowc=mysql_fetch_object($resultc))
{
?>
Subcategory==$rowc->ID) {echo
'selected=selected';} ?>>Name;?>
}
?>
/////////////////////////////
Radio Button && Check Box
////////////////////////////
status=='Active') {echo 'checked=checked';} ?> name="status"
id="status" value="Active">Active
status=='Inactive') {echo 'checked=checked';} ?> name="status" id="status"
value="Inactive">Inactive
/////////////////////////////
If same table se select box
////////////////////////////
status=='Active') {echo
'selected=selected';} ?> name="status" id="status"
value="Active">Active
status=='Inactive') {echo
'selected=selected';} ?>
name="status" id="status"
value="Inactive">Inactive
______________________________________________________________
===============
LOGIN
===============
include('conn.php');//connection file
session_start();
if(isset($_POST['submit']))
{
$query="select * from login where
Username='".$_POST['username']."' and
Password='".$_POST['Password']."'";
$result=mysql_query($query) or
die(mysql_error());
$row=mysql_fetch_object($result);
$count=mysql_num_rows($result);
echo $count;
if($count>0)
{
$_SESSION['ID']=$row->ID;
$_SESSION['Username']=$row->username;
header('location:category_add.php');
}
else
{
echo $error_msg="invalid user
name or password";
}
}
?>
------------------------------
==============
LOGOUT
==============
session_start();
$_SESSION['ID']=='';
unset($_SESSION['ID']);
session_destroy;
header('location:index.php');
?>
----------------------------------
=============
DELETE
=============
include('conn.php');
$query="delete from table_name
where ID='$_REQUEST[id]'";
mysql_query($query) or
die(mysql_error());
header('location:category_fetch.php');
?>
--------------------------------------
=======================
CHANGE
PASSWORD
=======================
include('conn.php');
if(isset($_POST['loging']))
{
$query="select * from fersh_html
where password='".$_POST['password']."'";
$result=mysql_query($query) or
die(mysql_error());
$count=mysql_num_rows($result);
$row=mysql_fetch_object($result);
echo $count;
if($count>0)
{
$update="update fersh_html set
password='".$_POST['npassword']."' where id='$row->ID'";
mysql_query($update) or die(mysql_error());
header('location:newtest.php');
}
else
{
echo $error_msg='please
eneter curret password';
}
}
?>
=======================
VALIDATION IN JAVASCRIPT
=======================
onclick="return valid()"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PASSWORD MATCH VALIDATION
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
onclick="return valid()"
function valid()
if(document.getElementById('npassword').value!=document.getElementById('cpassword').value)
{
alert('new password and confirm password do not match.')
document.getElementById('npassword').focus();
return false;
}
return true
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
PASSWORD VALIDATION WITH LENGTH
/////////////////////////////////////////
function valid()
step-1 (frist alert blank password)
if(document.getElementById('password').value=='')
{
alert('password is reqiured')
document.getElementById('password').focus();
return false;
}
step-2 (2nd alert password lenth)
if(document.getElementById('password').value.length
< 6 )
{ alert(" Your Password must be At least 6 Alphanumeric
Characters");
document.getElementById('password').focus();
document.getElementById('password').value="";
return false;
}
//////////////////////////
E-MAIL VALIDATION
/////////////////////////
if(document.getElementById('email').value==""){
alert('Enter
your email address');
document.getElementById('email').focus();
return
false;
}
var
email = document.getElementById('email');
var
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if
(!filter.test(email.value)) {
alert('Please
enter valid email address');
email.focus();
return
false;
}
if(email
already exit)
if(isset($_POST['submit']))
{
$email_exist="select
email from user_registration where
email='".$_POST['user_email']."'";
$emailexist=mysql_query($email_exist);
echo
$count=mysql_num_rows($emailexist);
if($count>1)
{
header("location:user-registration.php);
}
else
insert query
}
?>
::::::::::::::::::::::::::::::::::::
light box
.............................................''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''..............................................
if($row
> 0)
{
while($data
= mysql_fetch_object($res1))
{
?>
if(isset($_GET['id']))
{
$sql
= "select * from video_subcategory where Category='".$_GET['id']."'";
$res
= mysql_query($sql);
$row
= mysql_num_rows($res);
}
else
{
$sql
= "select * from video_subcategory";
$res
= mysql_query($sql);
$row
= mysql_num_rows($res);
}
===============================
GOOGLE MAP CODE
================================
**********************************************************************************************************
===========================================
Messsage echo fetch page and data change edit page
============================================
header('location:emp_table_list.php?msg=success');
if($_GET)
{
if($_GET['msg']=='success')
{
?>
Employee Data Successfully
updated
if($_GET['msg']=='del')
{
?>
successfully
deleted
}
?>
=============================
Radio Button edit
=============================
status=='Active') {echo
'checked=checked';} ?> name="status" id="status"
value="Active">Active
status=='Inactive') {echo
'checked=checked';} ?>
name="status" id="status"
value="Inactive">Inactive
//////////////////////////////////////////////////////////
-----------------------------------------------------------------------------------------------------------------
$con=mysql_connect('localhost','root','');
mysql_select_db('framecart',$con);
$id=base64_decode($_GET['id']);
$delete="update services_category
set Isdeleted='0' where id='$_GET[id]'";
mysql_query($delete) or
die(mysql_error());
echo
"";
/////////insert timeing/////////
$data['data']['Isdeleted']='1';
//////////////
/////////////////display/////////////
$selectQuery="select * from
services_category where Isdeleted='1' ";
///////////////
?>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ADD EDIT DELETE AND FETCH BY AJAX
METHED
include('conn.php');
if($_GET['act']=='save')
{
$query="insert into admins set
username='".$_GET['name']."',email='".$_GET['email']."',password='".$_GET['password']."',category='".$_GET['category']."',subcategory='".$_GET['subcategory']."'";
mysql_query($query) or
die(mysql_error());
echo "1";
}
if($_GET['act']=='del')
{
$query="delete from admins where
id='".$_GET['id']."'";
mysql_query($query) or
die(mysql_error());
echo "1";
}
if($_GET['act']=='upd')
{
$query="update admins set
username='".$_GET['name']."',email='".$_GET['email']."',password='".$_GET['password']."',category='".$_GET['category']."',subcategory='".$_GET['subcategory']."'";
$result=mysql_query($query) or die(mysql_error());
$row=mysql_fetct_object($result);
json_encode($row);
echo '1';
}
if($_GET['act']=='cate')
{
$query="select * from subcategory
where cid='".$_GET['id']."'";
$result=mysql_query($query) or
die(mysql_error());
while($row=mysql_fetch_object($result))
{?>
name; ?>
}
?>
$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%$%
step-1
creat tr id
For Example
step -2
select query
data select from table
For Example
$db=new
DB;
$selectQuery="select
* from category";
$result=$db->query($selectQuery);
$db->mysqlCount($result);
$fetchObject=$db->fetchObject();
foreach($fetchObject
as $row)
{
?>
Name; ?>
}
?>
last step and step -3
wsrite javascritp
For Example
function valid()
{
var
id=document.getElementById('category').value;
if(id==0)
{
document.getElementById('cat').style.visibility='hidden';
}
if(id==1)
{
document.getElementById('cat').style.visibility='hidden';
}
if(id==2)
{
//alert(id);
document.getElementById('cat').style.visibility='visible';
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
DOWNLOAD.PHP CODE
/////////////////////////////////////////////////////////////
$fullPath = $_GET['filename'];
if ($fd = fopen ($fullPath,
"r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf");
header("Content-Disposition: attachment;
filename=\"".$path_parts["basename"]."\"");
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition:
filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
//////////////////////////////////////////////////////////////////
|end download.php codeing |
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Search code with explaination
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if(isset($_GET['title']))
{
$selectQuery="select
* from attachment where title like '%".$_GET['title']."%'";
}
else
{
$selectQuery="select
* from attachment";
}
$db->query($selectQuery);
?>
Note :- title = table fied name that
is eachevery thik
attachment= table name
else for fetch all data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<!— Start Get
Local Time -->
$timezone = "Asia/Calcutta";
date_default_timezone_set($timezone);
echo date('h:i:s');
?>
<!— End Get Local
Time -->
<!— Start Get Date in specialformate -->
created));?>
<!— End Get Date in specialformate -->
First
letter uppar case in php
Ucfirst();
No comments:
Post a Comment