| Coding Forum Problems with your code? Let's hear about it. |
12-21-2004, 01:17 PM
|
#1 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
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();
}
|
|
|
12-21-2004, 01:25 PM
|
#2 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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.
|
|
|
12-21-2004, 01:35 PM
|
#3 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
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);
}
}
|
|
|
12-21-2004, 01:46 PM
|
#4 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
can you add:
Just after the insert query and post the full query here?
|
|
|
12-21-2004, 01:50 PM
|
#5 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
nothing is being displayed with the echo $q;
|
|
|
12-21-2004, 03:37 PM
|
#6 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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:
Under the line:
Code:
$row = $db->sql_fetchrow($r);
And post the output...?
|
|
|
12-21-2004, 03:41 PM
|
#7 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
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" }
|
|
|
12-21-2004, 03:47 PM
|
#8 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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:
Then post the result...
|
|
|
12-21-2004, 03:50 PM
|
#9 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
ouput, thanxs again:-
Code:
UPDATE cms_security SET ban_attempts = ban_attempts + 1 WHERE ban_id = '5'
|
|
|
12-21-2004, 04:00 PM
|
#10 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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...
|
|
|
12-21-2004, 04:07 PM
|
#11 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
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
|
|
|
12-21-2004, 04:53 PM
|
#12 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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) ."'";
|
|
|
12-21-2004, 04:59 PM
|
#13 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
i've done that what next i'm kinda lost and this book i got ain't helping lol
|
|
|
12-21-2004, 05:02 PM
|
#14 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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...
|
|
|
12-22-2004, 04:09 AM
|
#15 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
sorry i changed the bit SELECT to what you told me but it still is not putting the reason in the ban_reason field.
|
|
|
12-22-2004, 05:28 AM
|
#16 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
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...
|
|
|
12-22-2004, 05:39 AM
|
#17 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
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.
|
|
|
12-22-2004, 05:48 AM
|
#18 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
Can you echo the complete insert query please.
|
|
|
12-22-2004, 05:52 AM
|
#19 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
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;
|
|
|
12-22-2004, 08:46 AM
|
#20 (permalink)
|
|
Inactive
Join Date: 10-29-03
Posts: 249
Latest Blog: None
|
EDIT: Got it working 
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|