PHP, using Joomla, algorithm, networking if else, - php

Hi, I have a question, when i ever insert this code
if ($pointsreach>=$tempunilevel ){
mysql_query("UPDATE `incentives_table` SET pointsreach = pointsreach +500 where userid = '$newsponsorid' ");
the if statement does not work anymore
if (count($items) >0 && $lev <= 10 ){ // found get sponsor id for the next computation
$sponsorid = $items->upline; //sponsor id
but when i remove the
if ($pointsreach>=$tempunilevel ){
mysql_query("UPDATE `incentives_table` SET pointsreach = pointsreach +500 where userid = '$newsponsorid' ");
the statement works perfectly ...
$query = " UPDATE `#__eds_incentives_table` SET `temp` = `temp` + 25 where `userid` = '$sponsorid' ";
$db->setQuery($query);
$db->query();
$mote = $this->entryuni($sponsorid, $lev + 1, +25);
}
else {
return 'ok';
}
This is the code
public function entryuni($newsponsorid = null, $lev = 2, $fpv = 0)
{
$db = & JFactory::getDBO();
$query = "SELECT upline,fslot FROM `table` where userid = '$newsponsorid' ";
$db->setQuery($query);
$items = $db->loadObject();
$items = (!empty($items)) ? $items : array();
$queryreach = mysql_query("SELECT * FROM incentives_table WHERE userid = '$newsponsorid' ");
$fetchreach = mysql_fetch_array($queryreach);
$pointsreach=$fetchreach['pointsreach'];
$tempunilevel=$fetchreach['temp_unilevel'];
if ($pointsreach>=$tempunilevel ){
mysql_query("UPDATE `incentives_table` SET pointsreach = pointsreach +500 where userid = '$newsponsorid' ");
if (count($items) >0 && $lev <= 10 ){ // found get sponsor id for the next computation
$sponsorid = $items->upline; //sponsor id
$query = " UPDATE `#__eds_incentives_table` SET `temp` = `temp` + 25 where `userid` = '$sponsorid' ";
$db->setQuery($query);
$db->query();
$mote = $this->entryuni($sponsorid, $lev + 1, +25);
}
else {
return 'ok';
}

Related

Is it possible to set column to null after exire date has been reached?

What I am trying to do is a subscription system basically and I want it so when users subscription has ended (went over the expiry date) I want it to set the users group back to registered and also update a column to NULL.... how would I go about this? I'm assuming with cron
But what would I put in the cron.php? For it to check if its expired in the users table?
I have tried:
$sql22 = "SELECT `csgo`,`id`,`group_id`,`discord`,`username` FROM `users`";
$result2 = $db->query($sql22);
$datenow = date_create('now');
foreach($result2 as $item) {
$omyj = $item['username'];
$sql229 = "SELECT `expire`,`username` FROM `bans` WHERE `username` = '$omyj'";
$result29 = $db->query($sql229);
$row_cnt = $result29->num_rows;
$dateend = date_create($item['csgo']);
$diff = date_diff($datenow, $dateend);
//$out = $diff->format("Minutes:%i");
//print_r($datenow);
$hisuid = $item['id'];
if($diff->invert) {
if($diff->days >= 3) {
if($item['csgo'] != null && $row_cnt==0){
if($item['group_id'] == 5 || $item['group_id'] == 6){
$sql31 = "UPDATE `users` SET `csgo` = NULL WHERE `id` = '$hisuid'";
$result3 = $db->query($sql31);
$sql314 = "UPDATE `users` SET `group_id` = '4' WHERE `id` = '$hisuid'";
$result34 = $db->query($sql314);
}
}
}
}

Flow of loop not functioning properly

i have a code here that
if the $cost <= $row2['cost_disbursed'], it will execute the if statement here
but, it still deducts the values even if it is less than the value
while ( ($row = mysqli_fetch_array($query_result)) && ($row2 =
mysqli_fetch_array($query_result2)) ) {
if ( $cost <= $row2['cost_disbursed'] ) {
if ($cost <= $row['remaining']){
$sql= "UPDATE project set cost_disbursed = cost_disbursed - '$cost'
WHERE id = '$id'";
$result = mysqli_query($con,$sql);
$sql2= "UPDATE budget set remaining = remaining - '$cost' where id='1'";
$result2 = mysqli_query($con,$sql2);
echo "<script>window.alert('Balance successfully deducted!')
location.href = 'disbursed-Page.php'</script>";
}
}
else {
echo "<script>window.alert('Balance is not enough')
location.href = 'disbursed-Page.php'</script>";
}
}

How to check mysql fetched rows in while loop are same

how to check resulted row values from while loop are same,I need to update when status is completed from all results...
$result = $db->query("SELECT * FROM fy_working_staf_cstm WHERE task_id_c='".$t_id."'");
while($row = $db->fetchRow($result)){
++$tas;
$staff_id=$row['id_c'];
$result1 = $db->query("SELECT `status` FROM `fy_working_staf` WHERE id='".$staff_id."' AND `status`='Completed'");
$staf = $db->fetchByAssoc($result1);
$status = $staf['status'];
if($stat=='Completed')
{
++$tas1;
//$comple_staus='Closed_Closed';
}
}
if(($tas == $tas1) && ($tas1 !=0) )
{
$q = $db->query("UPDATE `tasks` SET `status`='Completed' WHERE id='".$t_id."' ");
$st = $db->fetchByAssoc($q);
}
Instead i can use break condition in this as :
while($row = $db->fetchRow($result)){
$staff_id=$row['id_c'];
$result1 = $db->query("SELECT `status` FROM `fy_working_staf` WHERE id='".$staff_id."' AND `status`='Completed'");
$staf = $db->fetchByAssoc($result1);
$status = $staf['status'];
if($stat!='Completed')
{
$comple_staus='Closed_Closed';
break;// will exit the loop when the row is not same
}
}

Notice: Trying to get property of non-object.. How to fix? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Here is the Code, from where error is coming :)
I hope that I'll get my answer quick!!!
function getSubs($id, $type, $start = null) {
if($type == 0) {
if(is_numeric($start)) {
if($start == 0) {
$start = '';
} else {
$start = 'AND `relations`.`id` < \''.$this->db->real_escape_string($start).'\'';
}
$limit = 'LIMIT '.($this->s_per_page + 1);
}
$query = sprintf("SELECT * FROM `relations`, `wp_users` WHERE `relations`.`subscriber` = '%s' AND `relations`.`leader` = `wp_users`.`ID` $start ORDER BY `relations`.`id` DESC $limit", $this->db->real_escape_string($id));
} else {
if(is_numeric($start)) {
if($start == 0) {
$start = '';
} else {
$start = 'AND `relations`.`id` < \''.$this->db->real_escape_string($start).'\'';
}
$limit = 'LIMIT '.($this->s_per_page + 1);
}
$query = sprintf("SELECT * FROM `relations`, `wp_users` WHERE `relations`.`leader` = '%s' AND `relations`.`subscriber` = `wp_users`.`ID` $start ORDER BY `relations`.`id` DESC $limit", $this->db->real_escape_string($id));
}
$result = $this->db->query($query);
while($row = $result->fetch_assoc()) {
$array [] = $row;
}
return array($array, $total = $result->num_rows);
}
function getActions($id, $likes = null, $type = null) {
global $LNG;
if($type == 1) {
$verify = $this->verifyLike($id);
$result = $this->db->query(sprintf("SELECT * FROM `messages`, `wp_users` WHERE `id` = '%s' AND `messages`.`uid` = `wp_users`.`ID`", $this->db->real_escape_string($id)));
if($result->num_rows == 0) {
return $LNG['like_message_not_exist'];
}
if(!$verify) {
$stmt = $this->db->prepare("INSERT INTO `likes` (`post`, `by`) VALUES ('{$this->db->real_escape_string($id)}', '{$this->db->real_escape_string($this->id)}')");
$stmt->execute();
$affected = $stmt->affected_rows;
$stmt->close();
if($affected) {
$this->db->query("UPDATE `messages` SET `likes` = `likes` + 1, `time` = `time` WHERE id = '{$this->db->real_escape_string($id)}'");
$user = $result->fetch_assoc();
$insertNotification = $this->db->query(sprintf("INSERT INTO `notifications` (`from`, `to`, `parent`, `type`, `read`) VALUES ('%s', '%s', '%s', '2', '0')", $this->db->real_escape_string($this->id), $user['uid'], $user['id']));
if($this->email_like) {
if($user['email_like'] && ($this->id !== $user['ID'])) {
sendMail($user['user_email'], sprintf($LNG['ttl_like_email'], $this->username), sprintf($LNG['like_email'], realName($user['user_login'], $user['first_name'], $user['last_name']), $this->url.'/index.php?a=profile&u='.$this->username, $this->username, $this->url.'/index.php?a=post&m='.$id, $this->title, $this->url.'/index.php?a=settings&b=notifications'), $this->email);
}
}
}
} else {
$x = 'already_liked';
}
} elseif($type == 2) {
$verify = $this->verifyLike($id);
$result = $this->db->query(sprintf("SELECT `id` FROM `messages` WHERE `id` = '%s'", $this->db->real_escape_string($id)));
if($result->num_rows == 0) {
return $LNG['like_message_not_exist'];
}
if($verify) {
$stmt = $this->db->prepare("DELETE FROM `likes` WHERE `post` = '{$this->db->real_escape_string($id)}' AND `by` = '{$this->db->real_escape_string($this->id)}'");
$stmt->execute();
$affected = $stmt->affected_rows;
$stmt->close();
if($affected) {
$this->db->query("UPDATE `messages` SET `likes` = `likes` - 1, `time` = `time` WHERE id = '{$this->db->real_escape_string($id)}'");
$this->db->query("DELETE FROM `notifications` WHERE `parent` = '{$this->db->real_escape_string($id)}' AND `type` = '2' AND `from` = '{$this->db->real_escape_string($this->id)}'");
}
} else {
$x = 'already_disliked';
}
}
if($likes == null) {
$query = sprintf("SELECT `likes` FROM `messages` WHERE `id` = '%s'", $this->db->real_escape_string($id));
$result = $this->db->query($query);
$get = $result->fetch_row();
$likes = $get[0];
}
$verify = $this->verifyLike($id);
if($verify) {
$state = $LNG['dislike'];
$y = 2;
} else {
$state = $LNG['like'];
$y = 1;
}
if($this->l_per_post) {
$query = sprintf("SELECT * FROM `likes`,`wp_users` WHERE `post` = '%s' and `likes`.`by` = `wp_users`.`ID` ORDER BY `likes`.`id` DESC LIMIT %s", $this->db->real_escape_string($id), $this->db->real_escape_string($this->l_per_post));
$result = $this->db->query($query);
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
$people = '';
foreach($array as $row) {
$people .= '<img src="'.$this->url.'/thumb.php?src='.$row['image'].'&w=25&h=25&t=a" title="'.realName($row['user_login'], $row['first_name'], $row['last_name']).' '.$LNG['liked_this'].'" /> ';
}
}
$actions = '<a onclick="doLike('.$id.', '.$y.')" id="doLike'.$id.'">'.$state.'</a> - <a onclick="focus_form('.$id.')">'.$LNG['comment'].'</a> - <a onclick="share('.$id.')">'.$LNG['share'].'</a> <div class="like_btn" id="like_btn'.$id.'"> '.$people.$likes.'</div>';
if(empty($this->id)) {
$actions = ''.$LNG['login_to_lcs'].' <div class="like_btn"> '.$people.$likes.'</div>';
}
if(isset($x)) {
return $LNG["$x"].' <div class="like_btn"> '.$likes.'</div>';
}
return $actions;
}
The notice "Trying to get property of non-object" couldn't be more clear. You are trying to read a property of something that is not an object.
For example:
$object = false;
echo $object->property; // Notice: Trying to get property of non-object
Probably it is happening because you are assuming every SQL query you are doing is succeeding. But if a SQL query has errors and fails to run, the call returns false instead of a results object.
Sinse you didn't even say what line you are having this problem it's not worth the effort of helping you any further here. Check if your queries are suceeding before trying to use the result and read the MySQL error message from $this->db->error to figure out whats going wrong.

My database didn't update

<?php
$db = new mysqli('localhost', 'root', 'root', 'chatting');
$query = "SELECT * FROM user WHERE state = 1 AND getp = 0";
$result = $db->query($query);
$num_result = $result->num_rows;
$mems = "";
for ($i = 0; $i < $num_result; $i++) {
$row = $result->fetch_assoc();
$mems = $row["userName"] . " " . $mems;
$query = "update `user` set `getp` = 1 where 'userName` = ".' $row["userName"] ';
$result = $db->prepare($query);
}
echo $mems;
?>
What I want I want to get all records that state = 1 and getp = 0, then inside loop and for every record I want to change the value of getp to 1, It's correct but don't know where is the wrong.
You forgot to execute() the update statement..
Also, note that this is not the correct way to prepare statements.. you will have to do something like this:
$query = $db->prepare("update `user` set `getp` = 1 where `userName` = :userName");
$query->bind_param(':userName',$row["userName"]);
$result = $query->execute();
Why doing it in a for loop? You could just do UPDATEuserSET getp = 1 WHERE state = 1 AND getp = 0;
While looping with for $i++? Why not while($row = $result->fetch_assoc()) { ... }?
However change the query to
$query = 'update `user` set `getp` = 1 where userName = "'. $row["userName"] .'"';
and don't forget to execute() it.
Please set your update command to:
$query = "update `user` set `getp` = 1 where `userName` = '". $row["userName"]. "'";

Categories