当前位置:  编程技术>php
本页文章导读:
    ▪php ajax 局部刷新注册验证的例子      1、ajax.js文件   代码示例: // JavaScript Document var xmlHttp; function S_xmlhttprequest() { xmlHttp=null; if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc. xmlHttp=new XMLHttpRequest(); } else if (window.ActiveXObje.........
    ▪php操作数据库入门实例(插入、编辑、删除)      1、首先,插入数据的代码。 <? $action=$_GET['action']; switch($action){ //添加记录 case"add"; $mail = trim(htmlspecialchars()($_POST["mail"])); $username = trim(htmlspecialchars($_POST["username"])); .........
    ▪php统计网站访问次数的一个简单方法      这里主要用到了session保存当前访问者,并将访问次数写入本地文件。 <? @session_start(); $counter = intval(file_get_contents("counter.dat")); if(!$_SESSION['']) { $_SESSION[''] = true; .........

[1]php ajax 局部刷新注册验证的例子
    来源: 互联网  发布时间: 2013-12-24

1、ajax.js文件
 

代码示例:

// JavaScript Document
var xmlHttp;
function S_xmlhttprequest()
{
xmlHttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}

function getName(name)
{

if(name = document.myform.name.value)
{
S_xmlhttprequest();
xmlHttp.open("get","data.php?name="+name,true);
xmlHttp.onreadystatechange = byname;
xmlHttp.send(null);
}

}

function byname()
{
if(xmlHttp.readyState ==1)
{
document.getElementById('name').innerHTML = "<font color=red>loading....</font>";
}
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var name = xmlHttp.responseText;
document.getElementById('name').innerHTML = name;
}
}
}
function getEmail(email)
{
var email = document.myform.email.value;
if(email =="")
{
alert("用户名不能为空");
document.myform.email.focus();
return false;
}
else
{
S_xmlhttprequest();
xmlHttp.open("get","data.php?email="+email,true);
xmlHttp.onreadystatechange = byemail;
xmlHttp.send(null);
}

}
function byemail()
{
if(xmlHttp.readyState ==1)
{
document.getElementById('email').innerHTML = "<font color=red>loading....</font>";
}
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var email = xmlHttp.responseText;
document.getElementById('email').innerHTML = email;
}
}
}

2、register.php文件
 

代码示例:
<title>注册页面_www.</title>
<script src="/blog_article/Ajax.js" language="javascript"></script>
<body>
<form action="" method="post" name="myform">
<table align="center">
<tr><td>用户名:</td><td><input type="text" name="name" value="" onblur="getName('name')"/></td><td><div id="name"><font color="#CC66CC">*用户名必填*</font></div></td></tr>
<tr><td>邮箱:</td><td><input type="text" name="email" value="" onblur="getEmail('email')"/></td><td><div id="email"><font color="#CC66CC">*邮箱必填*</font></div></td></tr>
</table>
</form>

3、data.php页面,用于ajax查询数据库。
 

代码示例:
<?
sleep(1);
$connt = mysql_connect()("localhost","root","123456");
mysql_select_db('test',$connt );
mysql_query()("set names 'gb2312'");
if($_GET['name'])
{
$name = $_GET['name'];
$sql = "select * from test where name='$name'";
$restul = mysql_query($sql);
$array = mysql_fetch_row($restul);
// print_r($array);
if(is_array($array))
{
echo "<font color='red'>该用户名已经存在</font>";
}
else
{
echo "<font color='red'>该用户名可以用</font>";
}
}
if($_GET['email'])
{
$name = $_GET['email'];
$sql = "select * from test where email='$email'";
$restul = mysql_query($sql);
$array = mysql_fetch_row($restul);
// print_r($array);
if(is_array($array))
{
echo "<font color='red'>该邮箱已存在</font>";
}
else
{
echo "<font color='red'>该邮箱可以用</font>";
}
}
?>

由此即可实现用户注册时局部刷新的功能了。


    
[2]php操作数据库入门实例(插入、编辑、删除)
    来源: 互联网  发布时间: 2013-12-24

1、首先,插入数据的代码。

<?  
 $action=$_GET['action'];  
 switch($action){  
  //添加记录  
  case"add";  
  $mail = trim(htmlspecialchars()($_POST["mail"]));  
  $username = trim(htmlspecialchars($_POST["username"]));  
  $tel = trim(htmlspecialchars($_POST["tel"]));  
  $fax = trim(htmlspecialchars($_POST["fax"]));  
  $company = trim(htmlspecialchars($_POST["company"]));  
  $address = trim(htmlspecialchars($_POST["address"]));  
  $sql="insert into crm_company (mail,username,tel,fax,company,address,addtime) values
 ('$mail','$username','$tel','$fax','$company','$address','$addtime')";  
  //echo $sql;  
  mysql_query()($sql,$conn);  
  print "<mce:script type="text/javascript"><!--location.href='/blog_article/c_companylist.html'; // --></mce:script>";//*/  
 }?> 

2、编辑指定的数据的代码

<?  
 $action=$_GET['action'];  
 switch($action){  
  //添加记录  
  case"edit";  
  $uid = trim(htmlspecialchars($_POST["uid"]));  
  $regtime = trim(htmlspecialchars($_POST["regtime"]));  
  $deadline = trim(htmlspecialchars($_POST["deadline"]));  
  $item = trim(htmlspecialchars($_POST["item2"]));  
  $price = trim(htmlspecialchars($_POST["price"]));  
  $product = trim(htmlspecialchars($_POST["product"]));  
  $content = trim(htmlspecialchars($_POST["content"]));  
 
  $sql="update crm_info set uid='$uid',regtime='$regtime',deadline='$deadline',item='$item',price='$price',product='$product',
content='$content' where id='$id'";  
  //echo $sql;  
  mysql_query($sql,$conn);  
  print "<mce:script type="text/javascript"><!-- location.href='/blog_article/c_infolist.html';  // --></mce:script>";//*/  
}?>

html:

 <form id="form1" name="form1" method="post"  action="/blog_article/action/edit/amp;id/lt;php echo $rs[.html'id'];?>" onSubmit="return checkadd()">
 </form> 

3、删除指定数据的代码
<a href="/blog_article/action/del/amp;id/lt; echo $rs[.html'id'];?>" onclick="return confirm('确定删除?')">删除</a>

<?  
 $action=$_GET['action'];  
 switch($action){  
  //删除记录  
  case"del";  
  $id=$_GET['id'];  
  $sql="delete from crm_info where id='$id'";  
  mysql_query($sql,$conn);  
  print "<mce:script type="text/javascript"><!--location.href='/blog_article/c_infolist.html';// --></mce:script>";  
  break;  
 }  
?>
为您推荐:
php mysql数据库操作类
php数据库操作类(实现表增删改查、取行数、查询多条数据等)
PHP数据库调用类的应用实例(详细注释)

    
[3]php统计网站访问次数的一个简单方法
    来源: 互联网  发布时间: 2013-12-24

这里主要用到了session保存当前访问者,并将访问次数写入本地文件。

<?  
    @session_start();  
    $counter = intval(file_get_contents("counter.dat"));  
    if(!$_SESSION[''])  
    {  
     $_SESSION[''] = true;  
     $counter++;  
     $fp = fopen("counter.dat","w");  
     fwrite($fp, $counter);  
     fclose($fp);  
    }  
?>

共访问:

<?php echo "$counter";?>

    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3