php基础2012

填写表单

<form id="form1" name="form1" method="post" action="save.php" enctype="multipart/form-data">
<input type="text" name="username" />
<input type="radio" value="0" checked="checked" name="xingbie"/>男 <input name="xingbie" type="radio" value="1" />女
<input type="submit" name="Submit" value="提交" />
</form>


保存到数据库

<?php
require_once("conn.php");

$username=$_POST["username"];
$xingbie=$_POST["xingbie"];
$riqi = date("Y-n-j G:i:s");


echo $username;
echo "<br>";
if ($xingbie==1){
  echo "女" ;
  echo "<br>" ;
}
else{
  echo "男";
  echo "<br>";
}
echo $xingbie;
echo "<br>";

$exec="insert into xuesheng(username,xingbie,jiontime) values ('".$username."','".$xingbie."','".$riqi."')";

mysql_query($exec);
echo "<script>alert('添加成功!');location.href='list.php';</script>";

?>
读取数据

<?php
require "conn.php"
?>
<?php
$result=mysql_query("select * from xuesheng");
while($rs=mysql_fetch_object($result))
{
?>
<?php echo "$rs->username"?>
<?php echo "$rs->xingbie"?>
<a href="mod.php?id=<?php echo "$rs->id"?>">修改</a>
<a href="del.php?id=<?php echo "$rs->id"?>">删除</a>
<?php
}
?> 
删除数据

<?php
require_once("conn.php");

$id=$_GET["id"];

$exec="delete from xuesheng where id='$id'";
mysql_query($exec);
echo "<script>alert('删除成功!');location.href='list.php';</script>";

?>

修改数据

<?php
require "conn.php";
$id = $_GET["id"];
$result=mysql_query("select * from xuesheng where id='$id'");
while($rs=mysql_fetch_object($result))
{
?>
<form id="form1" name="form1" method="post" action="modsave.php">
<input type="text" name="username" value="<?="$rs->username"?>"/>
<input type="radio" value="0" checked="checked" name="xingbie" <?php if ($rs->xingbie==0){
echo "checked=checked";
}?>/>男 <input name="xingbie" type="radio" value="1" <?php if ($rs->xingbie==1){
echo "checked=checked";
}?>/>女
<input type="submit" name="Submit" value="修改" />
</form>
<?php
}
?>
修改保存数据

<?php
require_once("conn.php");

$username=$_POST["username"];
$xingbie=$_POST["xingbie"];
$riqi = date("Y-n-j G:i:s");
$id = $_POST["id"];

echo $username;
echo "<br>";
if ($xingbie==1){
  echo "女" ;
  echo "<br>" ;
}
else{
  echo "男";
  echo "<br>";
}
echo $xingbie;
echo "<br>";
$exec="update xuesheng set username='$username',xingbie='$xingbie' where id='$id'";
mysql_query($exec);
echo "<script>alert('修改成功!');location.href='list.php';</script>";

?>

管理员登录

<form action="checklogin.php" method="post">
<input name="username" type="text" id="username">
<input name="password" type="password" id="password">
<input type="submit" name="Submit" value="Submit">
</form>

判断是不是管理员

<?php
require_once('conn.php');
session_start();
$username=$_POST["username"];
$password=$_POST["password"];
$exec="select * from ceshi where username='".$username."'";
if($result=mysql_query($exec))
{
  if($rs=mysql_fetch_object($result))
  {
    if($rs->password==$password)
    {
      $_SESSION["adminname"]=$username;
     
	   echo "<script>alert('ok!');location.href='index.php';</script>";
    }
    else
    {
      echo "<script>alert('Password Check Error!');location.href='login.php';</script>";
    }
  }
  else
  {
    echo "<script>alert('Username Check Error!');location.href='login.php';</script>";
  }
}
else
{
  echo "<script>alert('Database Connection Error!');location.href='login.php';</script>";
}
?> 
新打开页面判断是否有session

<?
session_start();
if($_SESSION['adminname']=='')
{
  echo "<script>alert('Please Login First');location.href='login.php';</script>";
}
?> 

数据库连接文件

<?php  
 $mysql_server_name='localhost';   
 $mysql_username='root';   
 $mysql_password='';   
 $mysql_database='shop';   
 $conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);  
 mysql_select_db($mysql_database,$conn); 
 mysql_query("set names gbk");
?>

400电话接口

<?php
set_time_limit(0);
header("content-type:text/html;charset=utf-8");
$ch = curl_init();
		$url ='http://zj.minicall.cn:12345/2014/interface/data/company.php';
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POST, 1);
        $request = "verifymethod=pwd&loginid=【企业编号】&loginpwd=".md5("【企业密码】")."&action=add&entity_name=二代02212哈哈呵呵啊啊&login_pwd=e10adc3949ba59abbe56e057f20f883e&pay_type=2&is_record=1&client_total=10&inbound_rate=0.3&outbound_rate=0.3&sms_rate=0.1&money=1&num400=【400号码】&exten=【分机号码】&queuetitle=默认队列&tel[]=01018610108782&tel[]=01015811181748";
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        //设定返回的数据是否自动显示
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
		echo $result;
curl_close($ch); //get data after login
?>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值