c-o-d-e Posted November 21, 2009 Share Posted November 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/ Share on other sites More sharing options...
cbrooks Posted November 21, 2009 Share Posted November 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962793 Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 Try something like this, $query = "INSERT INTO `Banned` (`username`, `time`, `expire`) VALUES('$username', '$bantime', '$expire')"; James. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962802 Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 Sorry for extra post but why have you got double open & closing bracets here ?, if(($query)) James. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962803 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962807 Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962811 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 The same problem occurs with the timestamp and the expiredate. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962816 Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962817 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962824 Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 Try this maybe. $timestamp = date("Y-m-d", strtotime('H:i:s')); $expire = $timestamp + $time; & it meant basically show me what the output is lol. James. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962830 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962837 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962842 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 Quick update. I did this <?php $timestamp = date("d-m-Y H:i:s", time()); $expire = $timestamp + $time; echo ''. $timestamp .'<br />' . $expire . ''; ?> It works [/code] Quote Link to comment https://forums.phpfreaks.com/topic/182436-why-doesnt-this-add-information-into-the-database/#findComment-962852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.