Jump to content

Problem with mysql php stuff


Ristiisa

Recommended Posts

Hello,im beginner with php and mysql,and i have an game,im learning on it etc,but i have problem,i want to make an energy,that it will update the energy with 5 on every 15 mins(for that im using cron jobs,i know how to use them),but i dont know how to make it

 

i want to make it like

it will add 5 energy into the energy column or smth,and the old one stays,so if it was 10,it will be 15.

and if its more then 100,it will put it to 100.

 

thanks,my english is kinda bad so yeah,i really would be happy if someone could help me and teach me it.

Link to comment
https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/
Share on other sites

Are you asking about MySQL or CRON? Which part are you having issues with? Writing the SQL? Creating the CRON job?

with MySQL,i know how to set up cron jobs,but problem is with the mysql thingy

 

 

i tried

("UPDATE users SET energy=energy+5 WHERE energy < 95");

but it wont work,oh and it should add energy to every playes who is in users table

idk why i cant edit the text in this forums anymore,wanted to write that full scripts is

 

<?php
$username = "gsagsa";
$password = "gsagas";
$hostname = "localhost"; 


$dbhandle = mysql_connect($hostname, $username, $password);
$selected = mysql_select_db("plapla",$dbhandle);

$set=array();

("UPDATE users SET energy=energy+5 WHERE energy < 95");
?>

take a look at http://php.net/manual/en/function.mysql-query.php

 

You have to execute the query,

 

mysql_query("UPDATE users SET energy=energy+5 WHERE energy < 95");
echo mysql_error();

 

The last line should tell you if something went wrong.  This isn't the cron job, but should move you the right direction.  It is likely though that there is something missing from this conversation though....

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.