Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: PHP not Working...

  1. #1
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP not Working...

    I have created a code taht only works on my XAMMP Program, nothing else. I have tried my brothers host that uses PHP, but I get this error:

    Code:
    Fatal error: Cannot redeclare link() in /home/mosthigh/public_html/codeindex2.php on line 4
    Here is my code:
    Code:
    <?
    echo "<table width='100%' style='font-weight:bold'><tr><td width='33%'>Code</td><td width='33%'>Started By</td><td width='33%'>Views</td></tr></table>";
    
    function link($val){
    $as=$val->getElementsByTagName('a');
    foreach($as as $a){
    return "<a href='".$a->getAttribute('href')."'>".$a->nodeValue."</a>";
    }}
    $c=1;
    for($i=0;$i<$c;$i++){
    $doc=new DOMDocument();
    @$doc->loadHTMLFile("http://smcodes.smfforfree3.com/index.php/board,8.".($i*15).".html");
    $tables=$doc->getElementsByTagName('table');
    if($i==0){
    $ltds=$doc->getElementsByTagName('td');
    foreach($ltds as $ltd){
    if($ltd->getAttribute('class')=="middletext" && eregi('go down',$ltd->nodeValue)){
    $las=$ltd->getElementsByTagName('a');
    foreach($las as $la){
    if($la->getAttribute('class')=="navPages"){
    $c++;
    }}}}}
    foreach($tables as $table){
    if($table->getAttribute('width')=="100%" && $table->getAttribute('border')=="0" && $table->getAttribute('cellspacing')=="1" && $table->getAttribute('cellpadding')=="4"){
    $trs=$table->getElementsByTagName('tr');
    foreach($trs as $tr){
    $topic=$tr->childNodes->item(4);
    $started=$tr->childNodes->item(6);
    $view=$tr->childNodes->item(10);
    if($topic->nodeValue == "" || $started->nodeValue == "" || $view->nodeValue == ""){
    }else if(eregi("When Using My Codes",$topic->nodeValue)){
    }else if($topic->nodeValue == "Started by" || $started->nodeValue == "Replies" || $view->nodeValue == "Last post"){
    }else{
    echo "<table width='100%'><tr><td width='33%'>".link($topic)."</td><td width='33%'>".link($started)."</td><td width='33%'>".$view->nodeValue."</td></table>";
    }}}}}
    ?>

  2. #2
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I think it depends on the PHP version. This script works on my version which is 5.22

    Just a tip, not all versions of PHP are happy for scripts to start <?

    Think you should try replacing it with <?php

  3. #3
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I just tried adding <?php and it still didn't work.

    I believe the hosting I use, the version of the PHP is 3.3.0. At least that is what it says in the PHP configuration setting.

  4. #4
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    It is probably too old. Are you running a local server? As in a web server from home?

    Why don't you try upgrading your version of PHP at least?

    The script you posted, even with the <? tag as you have written it, works from my home server.

  5. #5
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I can't upgrade it. Not the one I am useing on a host. It works fine on my home server.

  6. #6
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ah I see. I just uploaded the script to my online server which hosts 4.44 and it doesn't actually work there neither. But it does on my home server which hosts 5.22!!

    So, either someone else might know what the problem is, or you need to find a host that uses PHP 5 or above.

    Sorry there's nothing more I can do for you now!

  7. #7
    Join Date
    Dec 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I don't know where, but you'll probably have to find a manual on PHP3.x to find the functions that accomplish the same task. PHP 5.x is a whole lot different than PHP 3.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The answer is easy.

    "Cannot redeclare" means that a function of that name already exists. In PHP you can not ever redefine a function name.

    http://www.php.net/manual/en/function.link.php

    That is the link function.

    Using that name, even if you could, would be confusing.

    Find a unique, descriptive name for your functions
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now I am getting this error:
    Warning: domdocument() expects at least 1 parameter, 0 given in /home/mosthigh/public_html/codeindex2.php on line 11
    Code:
    <?php
    echo "<table width='100%' style='font-weight:bold'><tr><td width='33%'>Code</td><td width='33%'>Started By</td><td width='33%'>Views</td></tr></table>";
    
    function Moosey($val){
    $as=$val->getElementsByTagName('a');
    foreach($as as $a){
    return "<a href='".$a->getAttribute('href')."'>".$a->nodeValue."</a>";
    }}
    $c=1;
    for($i=0;$i<$c;$i++){
    $doc=new DOMDocument();
    @$doc->loadHTMLFile("http://smcodes.smfforfree3.com/index.php/board,8.".($c*15)."/sort,subject.html");
    $tables=$doc->getElementsByTagName('table');
    if($i==0){
    $ltds=$doc->getElementsByTagName('td');
    foreach($ltds as $ltd){
    if($ltd->getAttribute('class')=="middletext" && eregi('go down',$ltd->nodeValue)){
    $las=$ltd->getElementsByTagName('a');
    foreach($las as $la){
    if($la->getAttribute('class')=="navPages"){
    $c++;
    }}}}}
    foreach($tables as $table){
    if($table->getAttribute('width')=="100%" && $table->getAttribute('border')=="0" && $table->getAttribute('cellspacing')=="1" && $table->getAttribute('cellpadding')=="4"){
    $trs=$table->getElementsByTagName('tr');
    foreach($trs as $tr){
    $topic=$tr->childNodes->item(4);
    $started=$tr->childNodes->item(6);
    $view=$tr->childNodes->item(10);
    if($topic->nodeValue == "" || $started->nodeValue == "" || $view->nodeValue == ""){
    }else if(eregi("When Using My Codes",$topic->nodeValue)){
    }else if($topic->nodeValue == "Started by" || $started->nodeValue == "Replies" || $view->nodeValue == "Last post"){
    }else{
    echo "<table width='100%'><tr><td width='33%'>".Moosey($topic)."</td><td width='33%'>".Moosey($started)."</td><td width='33%'>".$view->nodeValue."</td></table>";
    }}}}}
    ?>

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $doc=new DOMDocument();
    Well, you need something like:
    $doc=new DOMDocument($somethinghere);

    But I don't know how to use that. I've never needed it.

    Did you write this script yourself? Or did you find it somewhere?

    It just seems to have some problems in general. I'm not sure what to suggest.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •