dual_alliance Posted October 5, 2006 Share Posted October 5, 2006 Hello,l attempted to make a code which would run via CRON once a day that made it so it -1 from anyone who has been banned. However after trying it didn't work... and l deleted the code by mistake. But could someone please show me how to make the code that will update the banned days column and subtract 1 from any user that is their?Thankyou,dual_alliance[b]Edit: [/b] Found the code of my hd, see bottom of page for it except it doesnt work. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/ Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 we have no way of giving you an exact query string without knowing what your fields are or how it is you are going about keeping track of banned people. please give some more info. p.s.- moving to sql forums. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104231 Share on other sites More sharing options...
printf Posted October 5, 2006 Share Posted October 5, 2006 Can you show your db scheme, relating to the ban user table...me! Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104233 Share on other sites More sharing options...
dual_alliance Posted October 5, 2006 Author Share Posted October 5, 2006 Oh ok ... DB is as follows:DB name: ban_mailRows:ban.idban.usernameban.daysban.reasonI hope that helps[b]Edit: [/b] I no how to do the MySQL side of it, its just the PHP side of things. And l think l posted by accident in the wrong catagory. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104240 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 okay if you already know your query string then just do a simple connection and query script:[code]<?php $conn = mysql_connect('localhost','username','password'); $db = mysql_select_db('dbname',$conn); $sql = "query string here"; $result = mysql_query($sql, $conn);?>[/code]that's a barebones version. dunno if you wanna throw in some error trapping/logging or whatever. Anyways. just make a file called blah.php or whatever and point your cron job to it. edit: p.s.- I guess this belongs in the php forums after all ;D Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104244 Share on other sites More sharing options...
dual_alliance Posted October 5, 2006 Author Share Posted October 5, 2006 Hey l found backup of the code after searching my hole hd ;D, well heres what l had...[code=php:0]<?phprequire_once('settings.php');// Connect to the database@mysql_connect("$dbhost", "$dbusername", "$dbpassword") or die ('Cannot connect to MySQL database');@mysql_select_db("$dbname") or die ('Cannot select database');$i = 1;$sql = "SELECT `ban.days` FROM `banned` WHERE `ban.days` >= '$i' ";$result = mysql_query($sql) or die("Problem with the query: $sql <br>" . mysql_error());$row = mysql_fetch_assoc($result);$i2 = $row['ban.days'];$ri = $i2 - $i;$sql1 = "UPDATE `banned` SET `ban.days` = '$i2 - 1' WHERE `ban.days`= '$i2' ";$result1 = mysql_query($sql1) or die(mysql_error());?>[/code]Maybe this gives you more of an idea of what l am trying to do. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104250 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 okay so now that you have your old script back...problem solved? Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104251 Share on other sites More sharing options...
dual_alliance Posted October 5, 2006 Author Share Posted October 5, 2006 Not really cause it doesn't work, as it only updates the first user it find then converts all the days to that so e.g first user is banned for 4 days, next 6, next 8. When l run the code it converts them all to 3. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104256 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 [code]<?php $conn = mysql_connect('localhost','username','password'); $db = mysql_select_db('dbname',$conn); $sql = "update tablename set column = column - 1 where column > 0"; $result = mysql_query($sql, $conn);?>[/code] Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104265 Share on other sites More sharing options...
dual_alliance Posted October 5, 2006 Author Share Posted October 5, 2006 What! that simple, l was thinking l was going to need while loops and all that. Thankyou very much Crayon Violent! ;D Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104269 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 thus is the magic of db queries :)p.s.- like i said earlier, that script is barebones and does nothing for error trapping/logging so you might wanna look into all that, unless you don't care about any of that... Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104280 Share on other sites More sharing options...
dual_alliance Posted October 5, 2006 Author Share Posted October 5, 2006 Well l have named the file random so no one will be able to guess it manually, so l don't think logging will be nesasary. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104286 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 i was thinking more like if for some reason the script failed to connect to the db or update the db properly, you should have an error trapping/logging mechanism in place to log that stuff so if something goes wrong, you will have clues. Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104288 Share on other sites More sharing options...
dual_alliance Posted October 5, 2006 Author Share Posted October 5, 2006 Hmm you got a point there... l probably will in the future.Since l don't need any more help l'll lock this :) Link to comment https://forums.phpfreaks.com/topic/23072-php-code-help-needed/#findComment-104327 Share on other sites More sharing options...
Recommended Posts