喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: [代码] 我练习的PHP连接MYSQL的例子,欢迎大家来帮我查错  
 
newbill
新手上路
Rank: 1



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是显示图片,谢谢先
2007-2-25 11:59 AM#1
查看资料  发短消息  顶部
 
c1a1o1
版主
Rank: 7Rank: 7Rank: 7
一品带刀护卫


UID 68669
精华 0
积分 8926
帖子 2347
金钱 8926 喜悦币
威望 0
人脉 0
阅读权限 100
注册 2006-2-17
状态 离线
[推荐阅读] 建议...
问题分解一点一点验证



生日礼物送什么www.feichanglipin.cn
生日礼物      补肾
2007-2-25 03:06 PM#2
查看资料  Blog  发短消息  QQ  顶部
 
newbill
新手上路
Rank: 1



UID 87724
精华 0
积分 17
帖子 11
金钱 17 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-28
状态 离线
[推荐阅读] 过年了,新年快乐
希望真有人能帮忙一下,谢谢,我查得很累
2007-2-26 04:10 AM#3
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.026180 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP