Jump to content

Recommended Posts

	if($_POST['bansub'])
{
	$username = addslashes(trim(mysql_real_escape_string($_POST['banuser'])));
    $time = addslashes(trim(mysql_real_escape_string($_POST['bansel'])));

	if(empty($username)){
	$error['username3'] = 'Username Required';
	} 

	if(!$error) 
	{
	$datetime = date("Y-m-d H:i:s");
	$timestamp = strtotime($datetime);
	$expire = $timestamp + $time;
	$query = "INSERT INTO Banned VALUES ('$username', '$bantime', '$expire')";
	if(($query))
 {
   echo 'User banned successfully!<br />';
 } else { echo 'Something has gone wrong, please try again<br />';
}
  } 
}

 

For some reason, when I fill out the form, it doesn't send it into the database.

 

I submit the form, no errors detected, it says "User banned successfully" but it doesn't actually put the user in the Banned table.

Why would this be?

unless you are not showing us all of the code, it looks like you are missing a mysql_query statement something like:

 

$result = mysql_query($query) or die(mysql_error());

 

this statement actually does the insert/update/select action on the database.

I don't know.. but it works with them or without. I'm use to putting them in.

 

This is the full code now. I made the changes suggested.

However.. The time doesn't actually come up. Also, the $time is in seconds, which should be added on to the current time, and must also come up in timestamps. Though it doesn't actually work.

 

	if($_POST['bansub'])
{
	$username = addslashes(trim(mysql_real_escape_string($_POST['banuser'])));
    $time = addslashes(trim(mysql_real_escape_string($_POST['bansel'])));

	if(empty($username)){
	$error['username3'] = 'Username Required';
	} 

	if(!isset($error)) 
	{
	$datetime = date("d-m-Y H:i:s");
	$timestamp = strtotime($datetime);
	$expire = $timestamp + $time;
	$query = mysql_query("INSERT INTO Banned (Username, BanDate, ExpireDate) VALUES ('$username', '$timestamp', '$expire')") or trigger_error('Query failed: '. mysql_error());
	if(($query))
 {
   echo 'User banned successfully!<br />';
 } else { echo 'Something has gone wrong, please try again<br />';
}
  } 
}

echo '<strong>Ban A User<br /></strong>
    Enter a users Username, and the time of ban and they will be banned.<br />'; ?><?php echo $error['username3'] ?>
<?php echo '<table><tr>
<td><label>Username:</label></td>
    <td><input type="text" name="banuser" id="banuser" /><br /></td></tr>
    <tr><td><label>Time:</label></td>
      <td><select name="bansel" id="bansel">
        <option>86400</option>
        <option>604800</option>
        <option>2592000</option>
        <option>31536000</option>
      </select></td>
      <td><input type="submit" name="bansub" id="bansub" value="Submit" /><br /></td></tr></table>
  <table><tr>
  <td><center>86400 = 1 Day</center></td></tr>
  <tr><td><center>604800 = 7 Days</center></td></tr>
  <tr><td><center>2592000 = 30 Days</center></td></tr>
  <tr><td><center>31536000 = 365 Days</center></td></tr></table>';
  echo '</form>';

 

If I ban the user for 86400. In the database, the $expire, comes up as 86421

For the $timestamp, it comes up as 0000-00-00 00:00:00 in the database.

It should be in the format as 00-00-0000 00:00:00 Though with the correct time and date. etc.

 

Any help?

I'll have a go at cleaning this up for you.

 



if($_POST['bansub']) {

$username = addslashes(trim(mysql_real_escape_string($_POST['banuser'])));

$time = addslashes(trim(mysql_real_escape_string($_POST['bansel'])));


if(empty($username)) {


$error['username3'] = 'Username Required';	

} 



if(!isset($error)) {


$datetime = date("Y-m-d H:i:s");	

$timestamp = strtotime($datetime);

$expire = $timestamp + $time;

$query = mysql_query("INSERT INTO `banned` (`username`, `bandate`, `expiredate`) VALUES ('$username', '$timestamp', '$expire')") or trigger_error('Query failed: '. mysql_error());


if(isset($query)) {

echo 'User banned successfully!<br />';	

} else {

echo 'Something has gone wrong, please try again<br />';



}
  } 
}

echo '<strong>Ban A User<br /></strong>
    Enter a users Username, and the time of ban and they will be banned.<br />' . $error['username3'] . ' <table><tr>
<td><label>Username:</label></td>
    <td><input type="text" name="banuser" id="banuser" /><br /></td></tr>
    <tr><td><label>Time:</label></td>
      <td><select name="bansel" id="bansel">
        <option value="86400">86400</option>
        <option value="604800">604800</option>
        <option value="2592000">2592000</option>
        <option value="31536000">31536000</option>
      </select></td>
      <td><input type="submit" name="bansub" id="bansub" value="Submit" /><br /></td>
</tr>
</table>
  <table><tr>
  <td><center>86400 = 1 Day</center></td></tr>
  <tr><td><center>604800 = 7 Days</center></td></tr>
  <tr><td><center>2592000 = 30 Days</center></td></tr>
  <tr><td><center>31536000 = 365 Days</center></td></tr></table>
  </form>';

 

Try this.

 

James.

The same problem occurs with the timestamp and the expiredate.

 

Ok. What happens ?, what does it output ?.

 

Echo these and post them here.

 

	



$datetime = date("d-m-Y H:i:s");

$timestamp = strtotime($datetime);

$expire = $timestamp + $time;

 

James.

When I click submit, the date and time in the database comes up: 0000-00-00 00:00:00

The Expiredate comes up as: 1258929666

When I put use the 86200 option.

 

Not to sure what you mean by echo-ing them and posting them here.

Ok, tried that, and now the date that comes up in the database is: 1970-01-01 00:00:00

For the expire date, when I use the value 86400. It comes up as 88370

 

What this is doing, as it has an add sign in the code. It gets the Year, 1970, and adds the 86400 ($time) on. Which equals 88370.

What it should do.. is add it onto the seconds, and it'll work out the rest of the date as it adds on. Also, the output should be displayed in a timestamp too.

 

The database part for the time, is datetime. For the expire, is a varchar..

Sorry for the double post.

If I echo what you told me. The output is.. (without the brackets things. There to say what the line is)

1970-01-01                        ($timestamp)

1970                                  ($expire)

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.