Member Avatar for doctorphp

Hi everyone. I am trying to work on a script that will ban a user from accessing my website for x amount of time. Here is the html and sql code.

HTML

<?php $date = 'd-m-Y';
						$endDate = strtotime($date); 
						?>
                        <tr>
                        	<th>Length of Ban</th>
                            <th>:</th>
                            <th>
                            <select name="period">
                            <optgroup label="Temporary Ban Options"> 
                            <option value="D_1">1 Day (<?php echo date($date, time()+((60*60)*24)); ?> 12:00 AM)</option> 
                            <option value="D_2">2 Days (<?php echo date($date, time()+((60*60)*48)); ?> 12:00 AM)</option> 
                            <option value="D_3">3 Days (<?php echo date($date, time()+((60*60)*72)); ?> 12:00 AM)</option> 
                            <option value="D_4">4 Days (<?php echo date($date, time()+((60*60)*96)); ?> 12:00 AM)</option> 
                            <option value="D_5">5 Days (<?php echo date($date, time()+((60*60)*120)); ?> 12:00 AM)</option> 
                            <option value="D_6">6 Days (<?php echo date($date, time()+((60*60)*144)); ?> 12:00 AM)</option> 
                            <option value="D_7" selected="selected">1 Week (<?php echo date($date, time()+((60*60)*168)); ?> 12:00 AM)</option> 		
                            <option value="D_14">2 Weeks (<?php echo date($date, time()+((60*60)*336)); ?> 12:00 AM)</option> 
                            <option value="D_21">1 Month (<?php echo date($date, time()+((60*60)*744)); ?> 12:00 AM)</option> 
                            <option value="Y_1">1 Year (<?php echo date($date, time()+((60*60)*8765)); ?> 12:00 AM)</option> 
                            <option value="Y_2">2 Years (<?php echo date($date, time()+((60*60)*17531)); ?> 12:00 AM)</option> 
                            </optgroup> 
                            <optgroup label="Permanent Ban Options"> 
                            <option value="PERMANENT">Permanent - Never Lift Ban</option> 
                            </optgroup> 
                            </select>
       					 	</th>
                        </tr>

SQL

CREATE TABLE  `megainstrumentals`.`userban` (
`user_id` INT( 10 ) NOT NULL ,
`admin_id` INT( 10 ) NOT NULL ,
`bandate` INT( 10 ) NOT NULL ,
`liftdate` INT( 10 ) NOT NULL ,
`reason` VARCHAR( 250 ) NOT NULL ,
PRIMARY KEY (  `user_id` )
) ENGINE = MYISAM ;

I am having trouble writing the code to ban the user and insert it into the db. I am mainly stuck on the bandate and the liftdate fields as I would not know how to grab the length of the ban from the select menu and put into the db and then check it when the user logs in. I am sorry if I have not provided enough information and any help would be really appreciated.

Thanks in advance.

Hi,

I would suggest that you use MySQL to work out the date intervals. More information can be found here.

If you then amend the values of your select box to correspond to MySQL interval units, e.g. 1 DAYS, 2 DAYS, ..., 1 WEEKS, 2 WEEKS, 1 MONTHS, etc.

You could then use the value (after sanitizing) directly in your query together with NOW() as the start date to determine the end date.

R.

Member Avatar for doctorphp

How would I turn that into PHP code?

If you make a start based on what I mentioned in my previous post:

amend the values of your select box to correspond to MySQL interval units, e.g. 1 DAYS, 2 DAYS, ..., 1 WEEKS, 2 WEEKS, 1 MONTHS, etc.

and

then use the value (after sanitizing) directly in your query together with NOW() as the start date to determine the end date

I will then help you with the specific parts you're having difficulty with.

R.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.