【为什么这段代码不能输出】教程文章相关的互联网学习教程文章

php 表单数据的获取代码

代码如下:<html> <head> <title>Form</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <form action="post.php" method="get" name="form1"> <table width="271" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="85"><div align="right">姓名:</div></td> <td width="186"><input name="username" type="text" id="username"></td> </tr> <tr> <td><...

PHP批量生成缩略图的代码

缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。<?php $config = array(); $config['path'] = "./"; $config['t_width'] = 120; $config['t_height'] = 98; $config['ignore'] = array("",".",".."); $config['prefix'] = "thumb_"; $done = 0; define("IMAGE_JPG", 2); define("ENDL", "\n"); if($handle = opendir($config['path'])) { while(false !== ($file = readdir($handle))) ...

PHP入门学习的几个不错的实例代码

1,php连接数据库 <?php $dbhost = 'localhost'; $dbuser = 'root'; //你的mysql用户名 $dbpass = '123456'; //你的mysql密码 $dbname = 'data'; //你的mysql库名 //连接本地数据库 $GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass); //打开数据库 mysql_select_db($dbname,$GLOBALS["conn"]); ?> 2.php读取数据库中,某一字段值 <?php //读取一列数据 $sql="select * from ec_admin"; $result = mysql_query($sql,$...

php URL编码解码函数代码

代码如下:<?php $url = "//www.gxlcms.com"; echo urlencode($url); //输出编码后的字符串 ?> 代码如下:<?php $url = "//www.gxlcms.com"; $newurl = urlencode($url); //首先对$url进行编码 echo urldecode($newurl); //输出解码后的字符串 ?>

php 异常处理实现代码

代码如下:<?php $path = "D:\\in.txt"; try //检测异常 { file_open($path); } catch(Exception $e) //捕获异常 { echo $e->getMessage(); } function file_open($path) { if(!file_exists($path)) //如果文件无法找到,抛出异常对象 { throw new Exception("文件无法找到", 1); } if(!fopen($path, "r")) //如果文件无法打开,抛出异常对象 { throw new Exception("文件无法打开", 2); } } ?> 代码如下:<?php $path = "D:\\in.txt...

php连接mysql数据库代码

代码如下:<?php mysql_connect("localhost", "root","1981427") //连接位于localhost的服务器,用户名为root ?> 代码如下:<?php @mysql_connect("localhost", "root","1981427") or die("数据库服务器连接失败"); ?> 代码如下:<?php @mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器 or die("数据库服务器连接失败"); @mysql_select_db("test") //选择数据库mydb or die("数据库不存在或不可...

php cookie 登录验证示例代码

代码如下:<html> <head> <title>Login</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <form name="form1" method="post" action="login.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="150"><div align="right">用户名:</div></td> <td width="150"><input type="text" name="username"></td> </tr> <tr> <td><div alig...

php 表单验证实现代码

代码如下:<html> <head> <title>Form</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script language="javascript" src="form.js" src="form.js"></script> </head> <body> <form action="post.php" method="get" name="form1" onsubmit="return form_sub()"> <table width="271" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="85"><div align="right">姓名:</...

php adodb分页实现代码

代码如下:<?php include("adodb/adodb.inc.php"); //包含adodb类库文件 include("adodb/adodb-pager.inc.php"); //包含adodb-pager类库文件 $conn = NewADOConnection('mysql'); //创建adodb对象,声明数据库类型为MySQL $conn->Connect("localhost", "root", "1981427", "test"); //连接数据库,其中mydb为数据库名 $sql = "select * from tablename1"; //定义要执行的SQL语句 $pager = new ADODB_Pager($conn, $sql); //根据连接...

php xml文件操作代码(一)

example.xml文件: 代码如下:<?php $xml = simplexml_load_file('example.xml'); //创建SimpleXML对象 print_r($xml); //输出XML ?> 代码如下:<?xml version='1.0'?> <departs> <depart> <name>production support</name> <employees> <employee> <serial_no>100001</serial_no> <name>Simon</name> <age>24</age> <birthday>1982-11-06</birthday> <salary>5000.00</salary> <bonus>1000.00</bonus> </employee> <employee> <ser...

php xml文件操作实现代码(二)

代码如下:<?php //创建一个新的DOM文档 $dom = new DomDocument(); //在根节点创建departs标签 $departs = $dom->createElement('departs'); $dom->appendChild($departs); //在departs标签下创建depart子标签 $depart = $dom->createElement('depart'); $departs->appendChild($depart); //在depart标签下创建employees子标签 $employees = $dom->createElement('employees'); $depart->appendChild($employees); //在employees标...

php cookis创建实现代码

代码如下:<?php setcookie("username","zhuzhao",time()+10);//设置cookis保存5秒 ?> 代码如下:<?php if(isset($_COOKIE["username"])) { echo $_COOKIE["username"]; } else { echo "cookie没有找到"; } ?>

PHP5 操作MySQL数据库基础代码

1. 建立数据库连接 代码如下:<?php $mysqli = new mysqli("localhost","root","","mydb"); ?> 建立一个数据库连接需要四个参数,分别为数据库地址、数据库访问用户名、数据库访问密码、数据库名称。除了使用上面的mysqli对象的构造方法建立数据库连接外,还可以调用其connect方法建立数据库的连接。 代码如下:<?php $mysqli = new mysqli(); $mysqli->connect("localhost","root","","mydb"); ?> 还可以通过mysqli对象的构造方...

PHP 判断变量类型实现代码

PHP 包括几个函数可以判断变量的类型,例如:gettype(),is_array(),is_float(),is_int(),is_object() 和 is_string()。 代码如下:<?php $s = "this is a string"; $i = 9; $arr = array(2,4,6); is_string($s); //返回TRUE,表示$s是一个字符串变量 is_string($i); //返回FALSE,表示$i不是一个字符串变量 is_array($arr); //返回TRUE,表示$arr是一个数组 is_array($s); //返回FALSE,表示$s不是一个数组 $str = "this is a ...

PHP5与MySQL数据库操作常用代码 收集【图】

1 建立数据库表: 代码如下:create database club; create table member( id int(11) not null auto_increment, no varchar(5) not null, name varchar(10) not null, age int(2) not null, level varchar(10) not null, sex tinyint(1) not null, date datetime not null, primary key(id) )engine=MyISAM default charset=GB2312; insert into member(id,no,name,age,level,sex,date)values (1,'A001','wanxia',30,'hj',1,'2008...