php ban script. Is this right?
Moderator: General Moderators
Re: php ban script. Is this right?
There is no error at all the IP is just not added to the database
Re: php ban script. Is this right?
The var dump SHOWS the correct IP address on the page but it is not going into the database
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: php ban script. Is this right?
@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?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: php ban script. Is this right?
I just want to insert the ip that it grabbed from the specific username into the banned_ips table in the database
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: php ban script. Is this right?
Ok.metjet2 wrote:The var dump SHOWS the correct IP address on the page but it is not going into the database
Code: Select all
<?php mysql_query("INSERT INTO banned_ips (banned_ips) VALUES ($ip)"); ?>
Last edited by social_experiment on Fri Dec 17, 2010 9:57 am, edited 1 time in total.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: php ban script. Is this right?
The error likely lies in your insertion query:
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:
Also, @social_experiment, you forgot the string delimiters in your query. And I doubt that the column is named "banned_ips". 
Code: Select all
INSERT INTO banned_ips ('$ip')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';- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: php ban script. Is this right?
I did indeed. Luckily you corrected a similar error earlier in the post so i don't think metjet2 will get it wrongsuperdezign wrote:Also, @social_experiment, you forgot the string delimiters in your query. And I doubt that the column is named "banned_ips".
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: php ban script. Is this right?
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?
Actually never mind (error on my part) the script now works
thank you guys so much 