Javis Posted January 28, 2008 Share Posted January 28, 2008 alright I'm new to php so im trying to learn some stuff and ive already done most of the basics. Im following a tut to build my first web site and when i debug my file i get this error Fatal error: Cannot redeclare hash_file() on line 180 the code on line 180 looks like this function hash_file ($strFilename) { $n = 0; for ($posFilename = strlen($strFilename) -1; $posFilename >= 0; $posFilename-- ) { $n *= 2; if ($n & 4096) { $n |= 1; } $n ^= (ord($strFilename[$posFilename])*11); $n &= 4095; } return sprintf ("%02o/%02o", ($n/64) & 63 , $n&63); } any one know what i should do? thanks in advanced Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/ Share on other sites More sharing options...
rhodesa Posted January 28, 2008 Share Posted January 28, 2008 PHP 5 already has a function called hash_file Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451207 Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 There is already a function built into php5 and above called hash_file. Rename your function to something else. Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451208 Share on other sites More sharing options...
Javis Posted January 28, 2008 Author Share Posted January 28, 2008 thorpe got an axample or you mean like any name? im extremely new to this stuff Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451209 Share on other sites More sharing options...
rhodesa Posted January 28, 2008 Share Posted January 28, 2008 I'm not familiar with the function, but it looks to do the same thing as PHPs version. My guess would be that the function was added so it would work on PHP4. Add an if around it to test it's existence: if(!function_exists('hash_file')){ function hash_file ($strFilename) { $n = 0; for ($posFilename = strlen($strFilename) -1; $posFilename >= 0; $posFilename-- ) { $n *= 2; if ($n & 4096) { $n |= 1; } $n ^= (ord($strFilename[$posFilename])*11); $n &= 4095; } return sprintf ("%02o/%02o", ($n/64) & 63 , $n&63); } } Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451211 Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 Any name will do. Just remember, when you call the function you'll need to use the same name. In fact you can probably proceed without the function at all and just use the newer built in hash_file function in its place. Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451212 Share on other sites More sharing options...
Javis Posted January 28, 2008 Author Share Posted January 28, 2008 lol i keep missing the reply button. any ways ill rename it something random. Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451215 Share on other sites More sharing options...
Javis Posted January 28, 2008 Author Share Posted January 28, 2008 got a new problem went through and fixed a few others but i dont know what to do with this one Call to a member function query() on a non-object on line 20 lines 19-22 look like the following $sSQL="Select * from ".$pho_main." where parent=$num order by name"; $q->query($DB, $sSQL); $rec=(object)$q->getrow(); if($q->numrows()==0){ any suggestions Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451235 Share on other sites More sharing options...
trq Posted January 28, 2008 Share Posted January 28, 2008 Where is $q defined? Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451239 Share on other sites More sharing options...
Javis Posted January 28, 2008 Author Share Posted January 28, 2008 your asking for this right? if not sorry $rec=(object)$q->getrow(); Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451242 Share on other sites More sharing options...
rhodesa Posted January 28, 2008 Share Posted January 28, 2008 No, on this line: $q->query($DB, $sSQL); You access the variable $q. Where is $q set? Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451248 Share on other sites More sharing options...
Javis Posted January 28, 2008 Author Share Posted January 28, 2008 umm fixed that one will post back if i have any more errors that i need help with Link to comment https://forums.phpfreaks.com/topic/88186-help-with-an-error/#findComment-451272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.