Jump to content


Photo

PHP Code Help Needed


  • This topic is locked This topic is locked
13 replies to this topic

#1 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 02:51 PM

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

Edit: Found the code of my hd, see bottom of page for it except it doesnt work.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 02:53 PM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 05 October 2006 - 02:54 PM

Can you show your db scheme, relating to the ban user table...


me!

#4 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 03:00 PM

Oh ok ... DB is as follows:

DB name: ban_mail

Rows:
ban.id
ban.username
ban.days
ban.reason

I hope that helps

Edit: 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.

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 03:05 PM

okay if you already know your query string then just do a simple connection and query script:

<?php
   $conn = mysql_connect('localhost','username','password');
   $db = mysql_select_db('dbname',$conn);
   $sql = "query string here";
   $result = mysql_query($sql, $conn);
?>

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
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 03:11 PM

Hey l found backup of the code after searching my hole hd ;D, well heres what l had...

<?php
require_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());
?>

Maybe this gives you more of an idea of what l am trying to do.

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 03:13 PM

okay so now that you have your old script back...problem solved?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 03:17 PM

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.

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 03:31 PM

<?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);
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 03:39 PM

What! that simple, l was thinking l was going to need while loops and all that.  Thankyou very much Crayon Violent! ;D

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 03:50 PM

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...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 03:53 PM

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.

#13 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 03:57 PM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#14 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 05 October 2006 - 04:16 PM

Hmm you got a point there...  l probably will in the future.

Since l don't need any more help l'll lock this :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users