Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Bidding Directory   ClickBooth Network   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 12-21-2004, 01:17 PM   #1 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
PHP Error Help

When i use my script i get this error:-
Quote:
Warning: Missing argument 3 for ban() on line 151
i think it has something to do with $on or $reason.

this is th ban() function

Code:
function Ban($ip, $on, $reason) { global $db; $q = "SELECT ban_id FROM ". BANLIST_TABLE ." WHERE ban_ip = '". encode_ip($ip) ."'"; $r = $db->sql_query($q); $row = $db->sql_fetchrow($r); if ($on) { if (!$row['ban_id']) { if ($ip != 'unknown') { $q = "INSERT INTO ". BANLIST_TABLE ." (ban_ip) VALUES ('". encode_ip($ip) ."')"; $db->sql_query($q); } } BanTwo($ip, $reason); } return Error(); }
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 12-21-2004, 01:25 PM   #2 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
This error is caused because you are calling the function without specifying the third function variable.

i.e. Somewhere (line 151) you have something like:
Code:
Ban('196.122.334.123', 'on');
You need to add in the third variable that you are sending to your function so that it looks like this:

Code:
Ban('196.122.334.123', 'on', 'very bad person');
Alternatively you can change your function definition so that the third variable is "optional" like this:

Code:
function Ban($ip, $on, $reason = false) { // Function code here }
You're not really making the variable "optional" but if it is missing then the function will assume thst it has the boolean value "false".

Hope this helps.
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 01:35 PM   #3 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
thanxs that fixed that but i'm having another problem.

It won't input what i want to the database for ban reason.

Code:
function BanTwo($ip, $reason) { global $db, $cms_root_path, $board_config, $phpEx, $table_prefix; include_once($cms_root_path .'language/lang_english/lang_main.'. $phpEx); if ($reason == '1') $trick = $lang['testb']; if ($reason == '2') $trick = $lang['testa']; if ($reason == '3') $trick = $lang['test0']; if ($reason == '4') $trick = $lang['test1']; if ($reason == '5') $trick = $lang['test2']; if ($reason == '6') $trick = $lang['test3']; if ($reason == '7') $trick = $lang['test4']; $q = "SELECT * FROM ". $table_prefix ."table1 WHERE ban_ip = '". encode_ip($ip) ."'"; $r = $db->sql_query($q); $row = $db->sql_fetchrow($r); if ($row['ban_id']) { $q = "UPDATE ". $table_prefix ."table1 SET ban_attempts = ban_attempts + 1 WHERE ban_id = '". $row['ban_id'] ."'"; $db->sql_query($q); } else { $q = "INSERT INTO ". $table_prefix ."table1 VALUES ('', '".encode_ip($ip)."', '".$trick."', '".time()."', '0')"; $db->sql_query($q); } }
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 01:46 PM   #4 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
can you add:

Code:
echo $q;
Just after the insert query and post the full query here?
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 01:50 PM   #5 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
nothing is being displayed with the echo $q;
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 03:37 PM   #6 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
Well, there are a whole host of reasons then - I expect that $row['ban_id'] is not equating to true and that the update query is running.

Your function is a big of a mess to be honest, you have passed variables, then globals, some sort of dynamic include, standard function calls such as encode_ip() and then you are passing the queries to a db class to execute them...

Can you put:

Code:
var_dump($row);
Under the line:

Code:
$row = $db->sql_fetchrow($r);
And post the output...?
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 03:41 PM   #7 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
output:-

Code:
array(5) { ["ban_id"]=> string(1) "5" ["ban_ip"]=> string(8) "8a000005" ["ban_reason"]=> string(0) "" ["ban_date"]=> string(10) "1103661489" ["ban_attempts"]=> string(2) "69" }
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 03:47 PM   #8 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
Ok, so ban_ip has a value so the if statement following it will equate to true.

One more, can you move the echo $q; so that it's outside the "if" statement but still insiode the function, so the last three lines look like:

Code:
} echo $q; }
Then post the result...
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 03:50 PM   #9 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
ouput, thanxs again:-

Code:
UPDATE cms_security SET ban_attempts = ban_attempts + 1 WHERE ban_id = '5'
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 04:00 PM   #10 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
Ok, well it clearly not inserting an IP but it is updating a counter for the number of times someone has tried to ban this IP.

The IP that you are sending to the function is already banned - so it is not entering it with your reason, it is simply incrementing a counter which is counting the number of times that this IP has been banned.

If you want to change or add a reason for why this IP has been banned then you need to change the queries. If this is what you are trying to do then you need to change the query to something like this:

Code:
$q = "UPDATE ". $table_prefix ."table1 SET ban_attempts = ban_attempts + 1, ban_reason = '".$reason."' WHERE ban_id = '". $row['ban_id'] ."'";
"ban_reason" should of course be whatever you have called that column...
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 04:07 PM   #11 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
that still didn't insert it. This bit:-
Code:
$q = "SELECT * FROM ". $table_prefix ."table1 WHERE ban_ip = '". encode_ip($ip) ."'"; $r = $db->sql_query($q); $row = $db->sql_fetchrow($r); if ($row['ban_id']) { $q = "UPDATE ". $table_prefix ."table1 SET ban_attempts = ban_attempts + 1 WHERE ban_id = '". $row['ban_id'] ."'"; $db->sql_query($q); } else { $q = "INSERT INTO ". $table_prefix ."table1 VALUES ('', '".encode_ip($ip)."', '".$trick."', '".time()."', '0')"; $db->sql_query($q); }
What that is supposed to do is.

If the IP is in the banlist with the same reason for banning increase attempts by 1.

If the IP is not in the database or the same IP has been banned again but for a different reason insert IP again, new reason, ban date and attempts to 1
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 04:53 PM   #12 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
It looks to me more like this:

Quote:
Originally Posted by Limit
If the IP is in the banlist with the same reason for banning increase attempts by 1.
There is no reference to "the reason" in the select above, so simply if this IP appears in the table it will increase the attempts by one.

Quote:
Originally Posted by Limit
If the IP is not in the database or the same IP has been banned again but for a different reason insert IP again, new reason, ban date and attempts to 1
It will only do an insert if the IP is not already in that table, for the same reason above.

You need to include the "reason" in the select statement, something like:

Code:
$q = "SELECT * FROM ". $table_prefix ."table1 WHERE ban_reason = '".$reason."' AND ban_ip = '". encode_ip($ip) ."'";
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 04:59 PM   #13 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
i've done that what next i'm kinda lost and this book i got ain't helping lol
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-21-2004, 05:02 PM   #14 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
Quote:
Originally Posted by Limit
i've done that what next i'm kinda lost and this book i got ain't helping lol
Well does it work now? You gotta give me more than that to go on...
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-22-2004, 04:09 AM   #15 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
sorry i changed the bit SELECT to what you told me but it still is not putting the reason in the ban_reason field.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-22-2004, 05:28 AM   #16 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
Ok, well I'll asume that the select statement is working correctly now. You now have to make sure that the insert query is inserting the new reason:

Depending on the value of $reason being 1, 2, 3.... you are selecting an item from the $lang array:

1. Make sure that you are passing a valid value for $reason (1-7)
2. Make sute thst the array $lang has values for each of the given keys (testa, testb, etc...)

Then echo the insert query and see wht the actual value of $trick is...
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-22-2004, 05:39 AM   #17 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
still no luck, it inserts the rest fine but not the reason and when i do:-

echo $lang['testa'];

it will get the lang value for testa fine but won't put it in the database.

Code:
if ($row['ban_id']) { $q = "UPDATE ". $table_prefix ."table1 SET ban_attempts = ban_attempts + 1 WHERE ban_id = '". $row['ban_id'] ."'"; $db->sql_query($q); } else { $q = "INSERT INTO ". $table_prefix ."table1 VALUES ('', '".encode_ip($ip)."', '".$trick."', '".time()."', '0')"; $db->sql_query($q); }

EDIT: I just put normal 'testing' in the insert field instead of $trick to see if it would input that and it did

Last edited by Limit : 12-22-2004 at 05:45 AM.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-22-2004, 05:48 AM   #18 (permalink)
v7n Mentor
 
jg_v7n's Avatar
 
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
iTrader: 0 / 0%
Latest Blog:
None

jg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web projg_v7n is a highly respected web pro
Can you echo the complete insert query please.
jg_v7n is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-22-2004, 05:52 AM   #19 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
when i echo the insert query after below nothing comes out:-

Code:
$q = "INSERT INTO ". $table_prefix ."table1 VALUES ('', '".encode_ip($ip)."', '".$trick."', '".time()."', '0')"; $db->sql_query($q); echo $q;
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-22-2004, 08:46 AM   #20 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
EDIT: Got it working
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On