Page 2 of 2

Re: php ban script. Is this right?

Posted: Wed Dec 15, 2010 5:35 pm
by metjet2
There is no error at all the IP is just not added to the database

Re: php ban script. Is this right?

Posted: Wed Dec 15, 2010 5:39 pm
by metjet2
The var dump SHOWS the correct IP address on the page but it is not going into the database

Re: php ban script. Is this right?

Posted: Thu Dec 16, 2010 1:02 am
by social_experiment
@metjet2 : What i meant was REMOVE mysql_result() completely but regardless, according to your picture there is no 'username' field in the table, that might be it?

Re: php ban script. Is this right?

Posted: Thu Dec 16, 2010 10:44 am
by metjet2
I just want to insert the ip that it grabbed from the specific username into the banned_ips table in the database

Re: php ban script. Is this right?

Posted: Thu Dec 16, 2010 12:51 pm
by social_experiment
metjet2 wrote:The var dump SHOWS the correct IP address on the page but it is not going into the database
Ok.

Code: Select all

<?php mysql_query("INSERT INTO banned_ips (banned_ips) VALUES ($ip)"); ?>
This should insert the data ok, here's the format of an INSERT sql query INSERT INTO tableName (field) VALUES (value)

Re: php ban script. Is this right?

Posted: Fri Dec 17, 2010 7:53 am
by superdezign
The error likely lies in your insertion query:

Code: Select all

INSERT INTO banned_ips ('$ip')
If you had error reporting on, MySQL would inform you that your query is malformed. You do not have the keyword VALUES (or VALUE) before you define your values. Also, you do not need to define the fields explicitly, but if you do not, your syntax will require that you define the value of all fields. By your description, your table has at least two fields: ID and IP. Your query only defines 1 of them, thus still being invalid.

Assuming that your table has only two columns, id and ip, the insertion can be correctly made a few ways:

Code: Select all

insert into `banned_ips` values (1, '$ip');
insert into `banned_ips` (`ip`) values ('$ip');
insert into `banned_ips` set `ip` = '$ip';
Also, @social_experiment, you forgot the string delimiters in your query. And I doubt that the column is named "banned_ips". :P

Re: php ban script. Is this right?

Posted: Fri Dec 17, 2010 10:03 am
by social_experiment
superdezign wrote:Also, @social_experiment, you forgot the string delimiters in your query. And I doubt that the column is named "banned_ips".
I did indeed. Luckily you corrected a similar error earlier in the post so i don't think metjet2 will get it wrong ;) Yip it's called ip actually, my bad.

Re: php ban script. Is this right?

Posted: Mon Dec 20, 2010 5:25 pm
by metjet2
I tried the 3 ways listed above..The ID field is being increased (before it was not so it is somewhat improving) but the ip is not going into the IP field

Re: php ban script. Is this right?

Posted: Mon Dec 20, 2010 5:30 pm
by metjet2
Actually never mind (error on my part) the script now works :D thank you guys so much :D