phpfetchurl源代码的简单介绍[20240423更新]
admin 发布:2024-04-23 00:33 98
本篇文章给大家谈谈phpfetchurl源代码,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、php登录页面完整代码连接数据库
- 2、【高分】急求用php写的购物车代码!!!!!(十万火急)如果您提供的好用还有加分!!!
- 3、加入php代码段后div莫名的不见了,在浏览器看源代码body里面啥都没有?
php登录页面完整代码连接数据库
创建conn.php,连接数据库。
$dns = 'mysql:host=127.0.0.1;dbname=test';
$username = 'root';
$password = 'root';
// 1.连接数据库,创建PDO对象
$pdo = new PDO($dns,$username,$password);
创建login.html,登陆页面。
用户名
密 码
创建login.php,验证账号密码。
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST["submit"])){
exit("错误执行");
}//检测是否有submit操作
include('conn.php');//链接数据库
$name = $_POST['name'];//post获得用户名表单值
$pwd = sha1($_POST['password']);//post获得用户密码单值
if ($name $pwd){//如果用户名和密码都不为空
$sql = "select * from user where username = '$name' and password='$pwd'";//检测数据库是否有对应的username和password的sql
$stmt = $pdo-prepare($sql);
$stmt-execute();
if($stmt-fetch(PDO::FETCH_BOUND)){//0 false 1 true
header("refresh:0;url=welcome.html");//如果成功跳转至welcome.html页面
exit;
}else{
echo "用户名或密码错误";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";//如果错误使用js 1秒后跳转到登录页面重试;
}
}else{//如果用户名或密码有空
echo "表单填写不完整";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";
//如果错误使用js 1秒后跳转到登录页面重试;
}
$pdo = null;
创建signup.html,注册页面
用户名:
密 码:
创建signup.php
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST['submit'])){
exit("错误执行");
}//判断是否有submit操作
$name=$_POST['name'];//post获取表单里的name
$pwd = sha1($_POST['password']);//post获取表单里的password
include('conn.php');//链接数据库
$sql="insert into user(id,username,password) values (null,'$name','$pwd')";//向数据库插入表单传来的值的sql
$stmt = $pdo-prepare($sql);
$stmt-execute();
$stmt-fetch(PDO::FETCH_BOUND);
if (!$stmt){
die('Error: ' . $stmt-getMessage());//如果sql执行失败输出错误
}else{
echo "注册成功";//成功输出注册成功
}
$pdo = null;//关闭数据库
【高分】急求用php写的购物车代码!!!!!(十万火急)如果您提供的好用还有加分!!!
我也要弄一个这种购物车,
我去写个,贴出来,【嘿嘿,今天上午新写的】。
我懒得新建数据库,用的是我的数据库。
你按照我的改一下就能用了
本人水平有限,高手请指正。
你,大,爷的,虽然不咋地,保证能用
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
经过调试,
//$my-add_cart(45,3,"茶几系列");//新增购物
//$my-updata_cart(13,13,8); //更新购物
//$my-del_cart(12,5,'Guest'); //删除一种购物
//$my-empty_cart('Guest'); //清空购物车
$ok=$my-get_cart('Guest'); //返回购物车
这些都可用
-------------------------------------------------------------------
?php
class Cart
{
public $totalCost=0; //商品总金额
function cart($host,$usr,$pwd,$db)
{
mysql_connect($host,$usr,$pwd) or die(mysql_error);
mysql_select_db($db) or die(mysql_error);
mysql_query("SET Names GBk");
//只要有人访问,就自动清除一天前所有没付款的订单;
$sql="delete FROM shopcart WHERE TO_DAYS( NOW( )) - TO_DAYS( ptime ) =1 and payment=0";
mysql_query($sql);
}
// 弹出提示
function alter($Str,$Url)
{
echo "Script language='JavaScript' alert('".$Str."');/Script";
echo "meta http-equiv=refresh content=0;URL=".$Url."";
}
//增加购物;三个参数:pid:产品ID,ptl:产品数量,pcid:产品类别
//查询数据库,是否存在此人在本日内订过本产品
//如果订过,那么数量累加,否则插入一个数据库行
function add_cart($pid,$ptl=1,$pcid)
{
if($ptl=100 || $ptl=0)
{
$this-alter("最多买99件,最少1件","index.php");
die();
}
if(!$_SESSION['usr']) { $usr='Guest';}
else { $usr=$_SESSION['usr'];}
$sql="select * from shopcart where pid='".$pid."' and usr='".$usr."' and pcid='".$pcid."'";
$ex=mysql_query($sql);
$ex1=mysql_fetch_array($ex);
if(!$ex1)
{
$sql="select * from product where ID='".$pid."' and class1='".$pcid."'";
$ok=mysql_query($sql);
$rs=mysql_fetch_array($ok);
if($rs)
{
$totalCost= $rs['Price'] * $ptl;
$sql="insert into shopcart(usr,pid,pname,ptl,price,pcid,psum,payment) Values(";
$sql.="'".$usr."',";
$sql.="'".$rs['ID']."',";
$sql.="'".$rs['Name']."',";
$sql.="'".$ptl."',";
$sql.="'".$rs['Price']."',";
$sql.="'".$rs['Class1']."',";
$sql.="'".$totalCost."',";
$sql.="'0')";
mysql_query($sql) or die(mysql_error());
if($ok) { $this-alter("购物成功","index.php"); }
else { $this-alter("购物失败","index.php"); }
}
else
{
$this-alter("不存在的商品,或者参数错误","index.php");
die();
}
}
else
{
$sql="update shopcart set ptl= ptl+1,psum = psum+price where ID='".$ex1['ID']."'";
mysql_query($sql);
$this-alter("更新数量成功","index.php");
}
}
//更新购物车的单个产品的数量;
function updata_cart($cid,$ptl,$pid)
{
if($ptl=100||$ptl=0)
{
$this-alter('产品数量不对!','index.php');
die();
}
$sql="select * from shopcart where ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!ok) { alter("参数发生错误","index.php");}
else
{
$sql="update shopcart set ptl='".$ptl."',psum=price * '".$ptl."' where ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!ok) { $this-alter("更新失败","index.php");}
else { $this-alter("更新成功","index.php");}
}
}
function del_cart($cid,$pid,$usr)
{
$sql="delete from shopcart where usr='".$usr."' and ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!$ok) {$this-alter("删除失败","index.php");}
else {$this-alter("删除成功","index.php");}
}
function empty_cart($usr)
{
$sql="delete from shopcart where usr='".$usr."'";
mysql_query($sql) or die(mysql_error);
}
function get_cart($usr)
{
$sql="select * from shopcart where usr='".$usr."'";
$ok=mysql_query($sql);
return $ok;
}
}
$my = new Cart("localhost","root","root","mybbs");
//$my-add_cart(45,3,"茶几系列");
//$my-updata_cart(13,13,8);
//$my-del_cart(12,5,'Guest');
//$my-empty_cart('Guest');
$ok=$my-get_cart('Admin');
echo "usr pid pname ptl price pcid psum payment ptime brhrbr";
while($rs=mysql_fetch_array($ok))
{
echo $rs[1]."-".$rs[2]."-".$rs[3]."-".$rs[4]."-".$rs[5]."-".$rs[6]."-".$rs[7]."-".$rs[8]."-".$rs[9]."br";
}
?
、、、、、、、、、、、、、、、、、SQL、、、、、、、、、、、、、、
CREATE TABLE IF NOT EXISTS `shopcart` (
`ID` int(10) NOT NULL auto_increment,
`usr` varchar(50) NOT NULL,
`pid` int(5) NOT NULL,
`pname` varchar(100) NOT NULL,
`ptl` int(3) NOT NULL,
`price` decimal(50,2) NOT NULL default '0.00',
`pcid` varchar(100) NOT NULL,
`psum` decimal(50,2) NOT NULL default '0.00',
`payment` tinyint(1) NOT NULL,
`ptime` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`)
)
product 里面用的ID CLASS1是
`ID` int(6) NOT NULL auto_increment,
`Class1` varchar(20) NOT NULL,
`Price` int(6) NOT NULL,
加入php代码段后div莫名的不见了,在浏览器看源代码body里面啥都没有?
如果下面的条件语句不满足,网页的BODY里面就会什么都没有:
if( $row = mysqli_fetch_array($result)){
建议在这个语句的else里面echo 一个提示,例如
}else echo "没有找到满足条件的数据";
关于phpfetchurl源代码和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-02ecshop3.0源代码(ecshop v41)[20240502更新]
- 05-02ie内核源代码(IE内核版本)[20240502更新]
- 05-02源代码百度云盘(源代码电影下载百度云)[20240502更新]
- 05-02网站源代码查看软件(查看网页源代码这个软件怎么使用)[20240502更新]
- 05-02电池均衡源代码(电池均衡系统)[20240502更新]
- 05-02个人网站html5源代码(个人网页源代码HTML)[20240502更新]
- 05-02怎么看手机app源代码(手机app源代码查看)[20240502更新]
- 05-01商业游戏引擎源代码下载(开源免费游戏引擎)[20240501更新]
- 05-01jqtab代码的简单介绍[20240501更新]
- 05-01知识库管理平台源代码(源代码库知网)[20240501更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接