Max registrations/accounts per ip, SQL.

Hello all,
I am a total noob in php and some VIP asked me to make something simple for our clubhouse;
A page where users can submit/input 2 codes through a textbox and store it in a database.

There are 2 things i want: max 2 submits/inputs per IP(to prevent abuse)(ip stored in database).
[php]$ip = $_SERVER[‘REMOTE_ADDR’];
$check = mysql_query(“select * from table where ipcolumn=’$ip’”);
if (mysql_num_rows($check) > 0)
$insertip = “insert into table (ipcolumn) values (’$ip’)”;[/php]

And i wanna catch the error when an user put in a code lower than 5 characters.
not something like:
[php]if ($textarea == “”){[/php]

This is where i am so far.

new.php
[php]<?php
include ‘includes/config.php’;

mysql_select_db($mysql_database, $con);
$sql="INSERT INTO users (code, code2)
VALUES

(’$_POST[code]’,’$_POST[code2]’)";

if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}else{

header ("Location: /thanks.php");
}

?>[/php]

includes/config.php
[php]<?php

$mysql_host = “myhost.com”;
$mysql_database = “mydb”;
$mysql_user = “myuser”;
$mysql_password = “mypass”;

$con = mysql_connect($mysql_host,$mysql_user,$mysql_password);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
?>[/php]

sql.sql
[php]–
– Table structure for table users

CREATE TABLE users (
code varchar(30) collate latin1_general_ci NOT NULL,
code2 varchar(32) collate latin1_general_ci default NULL,
timestamp int(11) unsigned NOT NULL,
PRIMARY KEY (code)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;[/php]

index.html
[php]
[/php][/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service