Help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

Help!

Post by masterphp »

I have wroted a php program handling "Message Board" system(total including 7 php files), but when I run from Apache server, some of the files always show me the following error, I have no idea how to debug this, can someone give me any help or hint? thanks!
I have Apache with PHP+MySQL envirnoment
following is my database information:
<?php
$DBHOST="http://localhost/htdocs";
$DBUSER="root";
$DBPWD="12345";
$DBNAME="guestbook";
?>
*************************error messages I got**************************
1.Parse error: syntax error, unexpected ',' in C:\AppServ\www\htdocs\search.php on line 64

2.Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'http' (11001) in C:\AppServ\www\htdocs\replylist.php on line 9

3.Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\AppServ\www\htdocs\replylist.php on line 10

4.Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\AppServ\www\htdocs\replylist.php on line 10

5.Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\htdocs\replylist.php on line 12

6.Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\htdocs\replylist.php on line 16

7.Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\htdocs\replylist.php on line 21
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help!

Post by Christopher »

The host should just be 'localhost'.
(#10850)
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

Re: Help!

Post by masterphp »

Thanks arborint! but after I changed to the following setting, I sitll got the same error! so why is that? I have tired following both ways! can anyone give me a help?
<?php
$DBHOST="localhost";
$DBUSER="root";
$DBPWD="12345";
$DBNAME="guestbook";
?>

<?php
$DBHOST="http://localhost";
$DBUSER="root";
$DBPWD="12345";
$DBNAME="guestbook";
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help!

Post by Christopher »

Show the code that is doing the connection. Are you sure all the information is correct?
(#10850)
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help!

Post by Jonah Bron »

Post what it says on line 64 in "search.php". Also, relevant post titles are always best :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Help!

Post by pickle »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Help!

Post by Mordred »

pickle wrote:
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
Actually I think that "Why?" is the best answer to a "Help!" thread - I mean, if the poster hasn't bothered to write a short description of his problem, why should anyone bother to answer? The mere fact that someone does is a sign of the greatness of this community ;)
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

Re: Help!

Post by masterphp »

The following is my "search.php" and "replylist.php" code, the error messages I got are pretty much related to those two php files.

Code: Select all

 
<!--sys_conf.inc:------------------------------>//This is just my sys_conf.inc file that I include in the search.php file
<?php
  $DBHOST="http://localhost";
  $DBUSER="root";
  $DBPWD="12345";
  $DBNAME="guestbook";
?>
<!--search.php:--------------------->
<?php
    require_once("sys_conf.inc");
    
    
    function search($keyword,$content) 
    { 
        $count=count($content); 
        $j=0; 
        $ArrSearch=array(); 
        for ($i=0;$i<$count;$i++) 
        {
            if (ereg($keyword,$content[$i]))    
            { 
                
                $ArrSearch[$j]=str_replace($keyword,"<font color=red><b>$keyword</b></font>",$content[$i]);
                $j++; 
            } 
        } 
        return $ArrSearch; 
    }
    
    
    function searchid($keyword,$rid,$content) 
    { 
        $count=count($content); 
        $j=0; 
        $Arrid=array(); 
        for ($i=0;$i<$count;$i++) 
        { 
            if (ereg($keyword,$content[$i]))    
            { 
                $Arrid[$j]=$rid[$i];
                $j++; 
            } 
        } 
        return $Arrid; 
    }
 
    $one_page_line=10; 
    $content=array();       
    $id=array();                
    $ArrSearch=array(); 
    $Arrid=array();         
    
    
    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);         
    mysql_select_db($DBNAME);
    $str="select rid,content from guestbook";
    $result=mysql_query($str,$link_id);
    
    $i=0;
    while(list($rid,$con)=mysql_fetch_row($result))
    {
        $content[$i]=$con;
        $id[$i]=$rid;
        $i++;
    }
    mysql_close($link_id);   
 
    if (isset($_POST["search"]) and isset($_POST["keyword"]) and $_POST["keyword"]!="") 
    { 
        $ArrSearch=search($_POST["keyword"],$content); 
        $Arrid=searchid($_POST["keyword"].,$id,$content); 
    }
    else
    {
        $ArrSearch=$content; 
        $Arrid=$id; 
    }
    //print_r($ArrSearch);
    //print_r($Arrid);
    $count =count($ArrSearch); 
?>
 
<!--replylist.php:--------------------->
<?php   
    require_once("sys_conf.inc");
    //Initial
    $one_page_line=10;  //Max_Page
    $reply_content=array();     
    
    
    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);         
    mysql_select_db($DBNAME);
    $str="select content from reply where bookid =".$_GET["recordid"];
    $result=mysql_query($str,$link_id);
    
    
    $i=0;
    while(list($con)=mysql_fetch_row($result))
    {
        $reply_content[$i]=$con;
        $i++;
    }
    mysql_close($link_id);   
 
    $count =count($reply_content); 
?>
<html>
    <head>
        <title>Look for reply</title>
    </head>
    <body>
        <?php include  "head.html"?>
        <table width="68%" border="0"> 
            <tr> 
            <td>            
            <?php 
            $int_page_count=$count;  
            $int_page_num=ceil($int_page_count/$one_page_line);
            echo "<font color=#CC33FF>page separate:"; 
            for ($i=1;$i<=$int_page_num;$i++) 
            { 
                    echo "<a href=booklist.php?recordid=".$_GET["recordid"]."&page=$i>".$i."</a>&nbsp;"; 
            } 
            echo "</font>"; 
            ?> 
            </td>
            <td><p align=right>Total<font color=red><?echo "$count"?></font>Messages</p></td> 
            </tr>
        </table> 
        <table width="68%" border="0" align="center"> 
        <? 
        if (!isset($page) or $page=="") 
            $page=1; 
        $text="";
        $begin_line=$int_page_count-($page-1)*$one_page_line; 
        if ($begin_line<$one_page_line)
            $one_page_line=$begin_line; 
    
        for ($j=$begin_line;$j>($begin_line-$one_page_line);$j--) 
        {           
            print_r ($reply_content[$j-1]);
        }
        ?> 
        </table> 
        <p align=center><a href="#" onclick=history.back()>Return</a></p>
        </body>
</html>
Last edited by masterphp on Mon Apr 07, 2008 3:18 pm, edited 2 times in total.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Help!

Post by Mordred »

masterphp wrote:... the error messages I got are pretty much related to those two php files.
Well, have you tried the same solutions? :banghead:
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help!

Post by califdon »

masterphp wrote:

Code: Select all

Parse error: syntax error, unexpected ',' in C:\AppServ\www\htdocs\search.php on line 64
I'd look at line 64
masterphp wrote:

Code: Select all

$Arrid=searchid($_POST["keyword"].,$id,$content);
earcaraxe
Forum Newbie
Posts: 5
Joined: Mon Apr 07, 2008 8:33 pm

Re: Help!

Post by earcaraxe »

I'm new here, and I hope I'm not stepping on Califdon's toes, but there shouldn't be a period after your $_POST["keyword"] on line 64. Just a comma. I always hate it when I get random punctuation in that's messing up my syntax, and it's often hard to find. Get rid of that and it'll eliminate that first error.

Also take out the "http://localhost" and make it just "localhost". That should help a bit.
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

Re: Help!

Post by masterphp »

Thanks a lot earcaraxe! it works now, yeah, it is hard to see that small error, thanks for your help.
Post Reply