newbill
新手上路

UID 87724
精华
0
积分 17
帖子 11
金钱 17 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-28
状态 离线
|
[广告]: q
m
我练习的PHP连接MYSQL的例子,欢迎大家来帮我查错
这是一个图片上传的例子,如果正常的话,应该是在一个页面的上面为head.html 下面的左边为Left.php
下面的右边再分上下,上为rtop.php 下为rbottom.php
如果大家有空就复制到自己机器上,帮忙调试一下,我自己忙了大半天还是不行,谢谢先
//下面是数据库TXT
drop database if exists eStar;
create database eStar;
use eStar;
create table Stars
(
StarID int(4) NOT NULL auto_increment,
FileName varchar(50),
FileSize bigint(32),
FileType varchar(50),
PRIMARY KEY(StarID)
);
//首页
//index.php
<html>
<head><title>图片上传和显示</title></head>
<frameset row="70,*">
<frame name="heading" noresize scrolling="no" src="head.htm">
<frameset cols="55%,*">
<frame name="left" src="left.php" scrolling="yes">
<frameset rows="120,*">
<frame name="rtop" src="rtop.html" noresize>
<frame name="rbottom" src="rbottom.php" scrolling="yes">
</frameset>
</frameset>
</frameset>
</html>
//首页的上面即Head.html部分
<html>
<body>
<center>
<h1>Welcome to my photosshow<h1>
</center>
</body>
</html>
//首页下面的左边
//left.php
<html>
<body>
<h3>face show</h3>
<?php
$cn=@mysql_connect('localhost','root','micronsky.net') or die("不能链接数据库
服务器");
$strSQL="select * from Stars";
$result=mysql_db_query("eStar",$strSQL,$cn);
$rownums=mysql_num_rows($result);
if($rownums>0)
{
if($rownums==1)
{$sid=1;}
else
{$sid=rand(1,$rownums);}
echo "<img src=show.php?sid=".$sid.">";
}
mysql_close($cn);
?>
</body>
</html>
//首页下面的右边
//rtop.php
<html>
<body>
<B>待上传的相片:<B>
<center>
<form name="main" enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="max_file_size" value="1000000">
<input type="file" name="imagefile" size="30"><br>
<input type="submit" name="ok" value="上传">
</form>
</center>
</body>
</html>
//rbottom.php
<?php
$cn=@mysql_connect('localhost','root','micronsky.net') or die("不能链接数据库");
$strSQL="select StarID,FileName,FileType,FileSize from Stars";
$result=mysql_db_query("eStar",$strSQL,$cn);
$rownums=mysql_num_rows($result);
echo "<table border=1>";
echo "<tr><td><b>编号</></td><td><b>文件名</b></td>".
"<td><b>类型</b></td><td><b>字节</b></td></tr>";
while($arr=mysql_fetch_row($result))
{
echo "<tr><td><a href=show.php?sid=".$arr[0].
"target=blank>".$arr[0]."</a></td>".
"<td>$arr[1]</td><td>$arr[2]</td>".
"<td>$arr[3]</td><td></tr>";
}
echo "</table>";
mysql_connect($cn);
?>
//下面为以上程序有引用到的show.php
<?php
if($sid)
{
$cn=@mysql_connect('localhost','root','micronsky.net') or die("不能连接数据库
服务器");
$strSQL="select FileName,FileType from Stars"."where StarID=".$sid;
$result=mysql_db_query("eStar",$strSQL,$cn);
$filename=mysql_result($result,0,"FileName");
$imagetype=mysql_result($result,0,"FileType");
//问题below
header("Content-Type:image/jpeg");
$url="http://localhost/myphp/photosup/stars/Stars".$sid.$filename;
Header("Content-Disposition:attachment;filename=$url");
readfile($url);
mysql_close($cn);
}
?>
//就是上面那么多了,希望有高手能帮忙调试一下,功能是由rtop.php上传图片,而left.php是显示图片,谢谢先
|
|