免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4850 | 回复: 7
打印 上一主题 下一主题

php源码分析问题(留言簿系统)已处理 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-03 09:18 |只看该作者 |倒序浏览
文件夹中共有三个php文件,一个image文件夹;
执行add.php和guestbook.php均报错,报错的一行都是:
$message_count=mysql_result($result,0,"title");
查找:$result=mysql_query($sqldo);
查找:$sqldo="select count(*) as title from $mytable where sub_id<1";@将其改为select web from ...也不行@
$mytable在config.php中定义如下:$mytable="guestbook";
在mysql客户端中show databases;出现有web数据项
show tables;出现空值 empty
不知道自己那里出错了,是否我应该手动填写table项呢?
请高手指点,下面是源代码!

[ 本帖最后由 kronos911 于 2005-11-3 12:43 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2005-11-03 09:19 |只看该作者

add.php

add.php
<?
        require("config.php");
        $sqldo="select count(*) as title from $mytable where sub_id<1";
        $result=mysql_query($sqldo);
        $message_count=mysql_result($result,0,"title");
?>
<table border="0" width="75%" cellspacing="0" cellpadding="0" align="center">
  <tr bgcolor="FFEAA2">
    <td width="100%" height="18" valign="bottom" align="right">&Aacute;&ocirc;&Ntilde;&Ocirc;×&Uuml;&Ecirc;&yacute;&pound;&ordm;<font color=red><?echo $message_count?></font> | <a href="guestbook.php">&iquest;&acute;&Aacute;&ocirc;&Ntilde;&Ocirc;</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  </tr>
</table>
<?
        if ($doadd)
        {
            $name=htmlspecialchars($name);
            $email=htmlspecialchars($email);
            $comefrom=htmlspecialchars($comefrom);
            $homepage=htmlspecialchars($homepage);
            $icq=htmlspecialchars($icq);
            $oicq=htmlspecialchars($oicq);
            $image=htmlspecialchars($image);
            $comment=htmlspecialchars($comment);
                if ($name&&$comment) {
                        $add_time=date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s");
                        $result=mysql_query("insert into $mytable (sub_id,name,email,comefrom,homepage,icq,oicq,image,comment,password,add_time) values ('$sub_id','$name','$email','$comefrom','$homepage','$icq','$oicq','$image','$comment','$password','$add_time')");
                        if ($notify) {
                                $message="$comment\n\n$name $email\n\n$add_time";
                                mail($admin_email, "&Oacute;&ETH;&ETH;&Acirc;&micro;&Auml;&Aacute;&ocirc;&Ntilde;&Ocirc;: ".$name, $message, "From: ".$email."\nReply-To: ".$email."\nX-Mailer: PHP/" . phpversion());
                        }
                        echo "<p align=\"center\">&Auml;ú&micro;&Auml;&Aacute;&ocirc;&Ntilde;&Ocirc;·&cent;&Euml;&Iacute;&sup3;&Eacute;&sup1;&brvbar;&pound;&not;&ETH;&raquo;&ETH;&raquo;&pound;&iexcl;<a href=\"guestbook.php\">&sup2;é&iquest;&acute;&Aacute;&ocirc;&Ntilde;&Ocirc;&Ccedil;&euml;·&micro;&raquo;&Oslash;</a></p>\n";
                }
                else {
                        echo "<p align=\"center\">&ETH;&Otilde;&Atilde;&ucirc;&ordm;&Iacute;&Auml;&Uacute;&Egrave;&Yacute;±&Oslash;&ETH;&euml;&Igrave;&icirc;&ETH;&acute;&pound;&iexcl;<a href=\"JavaScript:history.back()\">·&micro;&raquo;&Oslash;</a></p>\n";
                }
        }
        else {
                if ($reply&&$recid) {
                        echo "<p align=\"center\">&raquo;&Oslash;&cedil;&acute;&Aacute;&ocirc;&Ntilde;&Ocirc;</p>";
                        $sub_id="<input type=\"hidden\" name=\"sub_id\" value=\"$recid\">";
                }
                else {
                        echo "<p align=\"center\">&Igrave;&icirc;&ETH;&acute;&Aacute;&ocirc;&Ntilde;&Ocirc;</p>";
                }
                        echo "<form method=\"POST\" action=\"add.php\">
    <table border=\"0\" width=\"75%\" align=\"center\">
      <tr>
        <td>
          <div align=\"center\">
            <table border=\"0\" width=\"80%\" cellpadding=\"20\" cellspacing=\"0\">
              <tr>
                <td width=\"100%\" bgcolor=\"FFFBEC\">&ETH;&Otilde;&Atilde;&ucirc;: <input type=\"text\" name=\"name\" size=\"25\">$sub_id
                  &micro;&ccedil;×&Oacute;&Oacute;&Ecirc;&frac14;&thorn;: <input type=\"text\" name=\"email\" size=\"25\"><br>
                  &Agrave;&acute;×&Ocirc;: <input type=\"text\" name=\"comefrom\" size=\"25\"> &Ouml;÷&Ograve;&sup3;&micro;&Oslash;&Ouml;·: <input type=\"text\" name=\"homepage\" size=\"25\"><br>
                  OICQ: <input type=\"text\" name=\"oicq\" size=\"25\">
                  <p>±í&Ccedil;é: ";
                $con=1;
                while ( list( $key, $val ) = each( $images ) ) {
                        $checked="";
                        if ($con==1) {
                                $checked=" checked";
                                $con=0;
                        }
                        echo "<input type=\"radio\" value=\"$key\" name=\"image\"$checked><img border=\"0\" src=\"$imgdir/$key\" alt=\"$val\"> ";
                }
                echo "</p>\n                  <p><b>&Aacute;&ocirc;&Ntilde;&Ocirc;:</b><br>
                  <textarea rows=\"4\" name=\"comment\" cols=\"72\"></textarea></p>
                  <p><input type=\"submit\" value=\"·&cent;&Euml;&Iacute;&Aacute;&ocirc;&Ntilde;&Ocirc;\" name=\"doadd\"> <input type=\"reset\" value=\"&sup2;&Aacute;&micro;&ocirc;&Ouml;&Oslash;&ETH;&acute;\" name=\"B2\"></td>
              </tr>
            </table>
          </div>
        </td>
      </tr>
    </table>
    </center>
  </div>
</form>
";
        }
?>

论坛徽章:
0
3 [报告]
发表于 2005-11-03 09:20 |只看该作者

guestbook.php

guestbook.php
<?
        require("config.php";
        if (!$page)
        {
                $page=1;
        }
        $sqldo="select count(*) as title from $mytable where sub_id<1";
        $result=mysql_query($sqldo);
        $message_count=mysql_result($result,0,"title";
        $page_count=ceil($message_count/$page_size);
        $offset=($page-1)*$page_size;
        $sqldo="select * from $mytable where sub_id<1 order by id desc limit $offset, $page_size";
        $result=mysql_query($sqldo);
?>
<table border="0" width="70%" cellspacing="0" cellpadding="0" align="center">
  <tr bgcolor="FFEAA2">
    <td width="100%" height="18" valign="bottom" align="right">&Aacute;&ocirc;&Ntilde;&Ocirc;×&Uuml;&Ecirc;&yacute;&pound;&ordm;<font color=red><?echo $message_count?></font> | <a href="add.php">&ETH;&acute;&Aacute;&ocirc;&Ntilde;&Ocirc;</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  </tr>
</table>
<br>
<table border="0" width="70%" cellspacing="0" cellpadding="0" align="center">
<?
        if($result)
        {
                while($myrow=mysql_fetch_array($result))
                {
                        listtopic($myrow,"70%",1);
                        $sqldo2="select * from $mytable where sub_id=$myrow[id] order by add_time";
                        $result2=mysql_query($sqldo2);
                        if($result2)
                        {
                                $rows2=mysql_num_rows($result2);
                                if($rows2)
                                {
?>

  <tr>
    <td width="100%">
      <table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
        <tr>
          <td width="5%" bgcolor="FFFECC" align="center">&raquo;&Oslash;<br>&cedil;&acute;</td>
          <td width="95%">
<?
                                        while($myrow2=mysql_fetch_array($result2))
                                        {
                                                listtopic($myrow2,"100%",0);
                                                echo "  </table>";
                                        }
?>
                  </td>
        </tr>
      </table>
    </td>
  </tr>
<?
                                }
                        }

                        echo "  </table>
<br>
";
                }
                $prev_page=$page-1;
                $next_page=$page+1;
                echo "             <p align=\"center\">| ";
                if ($page<=1){
                        echo "&micro;&Uacute;&Ograve;&raquo;&Ograve;&sup3; | ";
                }
                else{
                        echo "<a href='$PATH_INFO?page=1'>&micro;&Uacute;&Ograve;&raquo;&Ograve;&sup3;</a> | ";
                }
                if ($prev_page<1){
                        echo "&Eacute;&Iuml;&Ograve;&raquo;&Ograve;&sup3; | ";
                }
                else{
                        echo "<a href='$PATH_INFO?page=$prev_page'>&Eacute;&Iuml;&Ograve;&raquo;&Ograve;&sup3;</a> | ";
                }
                if ($next_page>$page_count){
                        echo "&Iuml;&Acirc;&Ograve;&raquo;&Ograve;&sup3; | ";
                }
                else{
                        echo "<a href='$PATH_INFO?page=$next_page'>&Iuml;&Acirc;&Ograve;&raquo;&Ograve;&sup3;</a> | ";
                }
                if ($page>=$page_count){
                        echo "×&icirc;&ordm;ó&Ograve;&raquo;&Ograve;&sup3; |</p>\n";
                }
                else{
                        echo "<a href='$PATH_INFO?page=$page_count'>×&icirc;&ordm;ó&Ograve;&raquo;&Ograve;&sup3;</a> |</p>\n";
                }
        }

        function listtopic($myrow,$this_table_width,$is_reply)
        {
                        global $imgdir;
                        $comment=nl2br($myrow[comment]);
                        if ($myrow[email]) {
                                $line1_left="<img border=\"0\" src=\"$imgdir\\$myrow[image]\"> <a href=\"mailtomyrow[email]\">$myrow[name]</a>";
                        }
                        else {
                                $line1_left="<img border=\"0\" src=\"$imgdir\\$myrow[image]\"> $myrow[name]";
                        }
                        if ($myrow[comefrom]) {
                                $line1_left .= "&nbsp;&nbsp;&Agrave;&acute;×&Ocirc;: $myrow[comefrom]";
                        }
                        else {
                                $line1_right="";
                        }
                        if ($myrow[oicq]) {
                                $line1_right .= " <img border=\"0\" src=\"$imgdir\\oicq.gif\" alt=\"OICQmyrow[oicq]\">";
                        }
                        if ($myrow[homepage]) {
                                $line1_right .= " <a href=\"$myrow[homepage]\" target=\"_blank\"><img border=\"0\" src=\"$imgdir\\homepage.gif\" alt=\"&Ouml;÷&Ograve;&sup3;myrow[homepage]\"></a>";
                        }
                        if ($is_reply) {
                                $toolsbar="<a href=\"add.php?reply=1&recid=$myrow[id]\" $table_head_bodystyle>&raquo;&Oslash;&cedil;&acute;</a>&nbsp;";
                        }
                        $toolsbar .= "&ETH;&THORN;&cedil;&Auml;&nbsp;&Eacute;&frac34;&sup3;&yacute;&nbsp;";
?>
  <table border="0" width="<?echo $this_table_width?>" align="center">
    <tr>
      <td width="100%" bgcolor="fff8d9">
        <table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td width="50%"><?echo $line1_left?></td>
            <td width="50%" align="right"><?echo $line1_right?>&nbsp;</td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="100%" bgcolor="FFFBEC"><?echo $comment?></td>
    </tr>
    <tr>
      <td width="100%" bgcolor="FFFBEC">
        <table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td width="50%">&Aacute;&ocirc;&Ntilde;&Ocirc;&Ecirc;±&frac14;&auml;&pound;&ordm;<?echo $myrow[add_time]?></td>
            <td width="50%" align="right"><?echo $toolsbar?></td>
          </tr>
        </table>
      </td>
    </tr>
<?
}
?>

论坛徽章:
0
4 [报告]
发表于 2005-11-03 09:21 |只看该作者

config.php

config.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>PHP4.0 +MYSQL &Aacute;&ocirc;&Ntilde;&Ocirc;±&frac34;</title>
<style type="text/css">
<!--
input { font-size:9pt; }
A:link {text-decoration: underline; font-size:9pt;color:000059}
A:visited {text-decoration: underline; font-size:9pt;color:000059}
A:active {text-decoration: underline; font-size:9pt}
A:hover {text-decoration:underline;color:red}
body,table {font-size: 9pt}
tr,td{font-size:9pt}
-->
</style>
</head>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<center><font color=red size=6>PHP4.0+MYSQL &Aacute;&ocirc;&Ntilde;&Ocirc;±&frac34;</font></center><br>
<?
        $dbuser=mysql_connect('localhost','root','mysql');
        $mydb=mysql_select_db('web',$dbuser);
        $mytable="guestbook";        // ±í&Atilde;&ucirc;
        $page_size=8;
        $notify=1;
        $imgdir="images";

        $images=array( "say.gif" => "&Euml;&aelig;±&atilde;&Euml;&micro;&Euml;&micro;",
                                "happy.gif" => "&cedil;&szlig;&ETH;&Euml;",
                                "sad.gif" => "±&macr;&Eacute;&Euml;",
                                "toohappy.gif" => "&acute;ó&ETH;&brvbar;",
                                "wilk.gif" => "&Otilde;&pound;&Ntilde;&Ucirc;",
                                "warning.gif" => "&frac34;&macr;&cedil;&aelig;",
                                "question.gif" => "&Icirc;&Ecirc;&Igrave;&acirc;",
                                "reply.gif" => "&raquo;&Oslash;&acute;&eth;",
                                "attention.gif" => "×&cent;&Ograve;&acirc;",
                                "agree.gif" => "&Iacute;&not;&Ograve;&acirc;",
                                "other.gif" => "&ordm;&Aring;&Iacute;&acirc;" );
?>

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
5 [报告]
发表于 2005-11-03 09:26 |只看该作者
原帖由 kronos911 于 2005-11-3 09:18 发表
文件夹中共有三个php文件,一个image文件夹;
执行add.php和guestbook.php均报错,报错的一行都是:
$message_count=mysql_result($result,0,"title");
查找:$result=mysql_query($sqldo);
查找: ...


报错?
报什么错?
然后,为什么报这个错?

论坛徽章:
0
6 [报告]
发表于 2005-11-03 09:52 |只看该作者
我在freebsd 5.4+apache2+php4中访问页面guestbook.php出现:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/server/apache2/htdocs/test/89/guestbook.php on line 9

访问add.php
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/server/apache2/htdocs/test/89/add.php on line 5

论坛徽章:
0
7 [报告]
发表于 2005-11-03 10:24 |只看该作者
在这个系统中,需要我手动create table 么?
这个config.php能否自己添加table表项!?

论坛徽章:
0
8 [报告]
发表于 2005-11-03 12:43 |只看该作者
问题找到了:文中需要的表项guestbook 需要手动建立!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP