i am stuck in a code, which is working fine but not all the time, it works for 4 transactions after that it shows an undefined offset error, which i can not figure out why it is occurring after running for four times, here is the code
<?php
$Selectlatest=mysqli_query($connection,"Select * from pos_order order by transaction_id desc limit 0,1");
$row_Selectlatest=mysqli_fetch_array($Selectlatest);
if(mysqli_num_rows($Selectlatest)==0){
$num = 001;
$invoice_no = date('dmy').$num;
}
$new = str_split($row_Selectlatest['invoice_no'],6);
$invoice_no= date('dmy').$new[1]+1 ;
?>
it works fine but after 4 consecutive transaction it shows an error which is
Notice: Undefined offset: 1 in C:\xampp\htdocs\Point_of_sale\admin\cart.php on line 60
How to solve it or any other way of generating the invoice or kind of referance no, which increases after checking the previous number from database?
Related
Tried almost dozen of thing with Mysql function (IFNULL,COALESCE,if condition etc) and PHP but nothing work for me. it simple query I want 0 (zero) output if there is no fines against employee. Query works fine when I add emp_id in table(emp_fines).
$query_str="SELECT SUM(amount) AS fines FROM `emp_fines`
WHERE MONTH(P_date) = MONTH(CURDATE()) AND emp_id ='".$em_cod."'
GROUP BY emp_id";
$query=$this->db->query($query_str);
$record=$query->row();
if (is_int($record->fines))
echo "0";
else
echo $record->fines;
using codeigniter, it gives below error!!
Severity: Notice Message: Trying to get property of non-object Filename: backend/dashboard.php eLine Number: 350
Thanks for #Akina for helping me. Finally below code works
$query_str="SELECT SUM(amount) AS fines FROM `emp_fines` WHERE MONTH(P_date) = MONTH(CURDATE()) AND emp_id ='".$em_cod."'"; //echo $query_str;
$query=$this->db->query($query_str);
$record=$query->row();
if ($record->fines===NULL)
echo "0";
else
echo $record->fines;
it should use
if(is_null($record->fines)){
// codes Here
}
and thank you for dropping in to help me.
currently i am trying to bring an old mafia game up to date for my own personal use as no one uses them now, and am stuck using objects which i have never used before.
The error i get is :
Notice: Trying to get property 'message' of non-object in C:\wamp64\www\mafia\Send.php on line 67
Here is the code
$query=mysqli_query($connection,"SELECT * FROM messages WHERE f='$ownusername' ORDER by id DESC LIMIT 3");
$info = mysqli_fetch_object($query);
$fetch=mysqli_fetch_object(mysqli_query($connection,"SELECT * FROM autospam LIMIT 1"));
if ($info->message == $message && $fetch->c == 1){
mysqli_query($connection,"UPDATE users SET mute='1', mutedby='Spamming' WHERE username='$ownusername'");
echo "You have been muted!";
}
This has been fixed thanks to Dmitry, for pointing me in the right direction, i found that the id in the sql insert was the error, where it was trying to insert an empty value into an auto increment table.
I removed the ID from the sql insert and all is working perfectly
I am trying to create an admin panel for my website. I use this code on my dashboard to count the number of users (and similar for the blog posts etc.:
//get result
$data = mysql_query("SELECT count(user_id) AS total FROM account_users");
$info = mysql_fetch_assoc($data);
//output result
echo "Rows found :" . $info['total'];
When I enter this code and view the page, this is the result:
Rows found :
As you can see, the number is not visible.
I tried to execute the code in the SQL section of PHPMyAdmin, and the result is 1 (and there is 1 row in the database, so that is correct!)
How is this possible? (And can you help me?)
Update on first comment:
I added the code he told me to, but it isn't going better.....
Error I'm getting now:
Notice: Undefined index: auth in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/index.php on line 9
Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/index.php on line 19
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/index.php on line 20
Rows found :
Notice: Undefined index: username in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/nav.php on line 3
mysql_query is deprecated.
Use mysqli_query. Try:
$con=mysqli_connect("localhost","my_user","my_password","my_db");
$sql="SELECT count(user_id) AS total FROM account_users";
$result=mysqli_query($con,$sql);
// Associative array
$row=mysqli_fetch_assoc($result);
echo "Rows found :" . $row['total'];
I want to make a list of all my users, so I used the following SQL query:
"SELECT Username FROM inloggen"
which works perfectly fine when I run it in phpMyAdmin and when I use
$list = mysql_fetch_array(mysql_query("SELECT Username FROM inloggen")); in php,
echo "<p> $list[0] </p>"; correctly returns the first user, but echo "<p> $list[1] </p>"; and higher all return an Undefined offset error, even though I have 6 users in my database.
Does anyone know why this happens?
So I'm having a very strange issue and am not quite sure what to think about it...
I have a standard database query doing a select on a table. It returns a resource, num_rows = 101, and it will fetch rows up to row 42 at which point it simply stops all script execution, no errors, not timing out (takes less than a sec to get the 42 rows) ... I can't provide a link but here's the code in question...
$select2 = "SELECT * FROM `$dbname`.`$file" . "_settings` WHERE `weight` <> 0 ORDER BY `count` ASC";
$result = mysql_query($select2);
$lpcnt = 0;
$numrows = mysql_num_rows($result);
while ($display = mysql_fetch_array($result, MYSQL_ASSOC)){
/* This will print out 42 times */
echo '<pre>In The LOOP, row('.$lpcnt.'):<br>NumRows: '.$numrows.'<br>';
print_r($display);
echo '</pre><br/>';
$domRows[] = $display;
$aTotal[] = $display['count'];
$aTotWeight[] = $display['weight'];
//debug vars
$d['url'] = $display['url'];
$d['total'] = $total;
$d['count'] = $display['count'];
$d['weight'] = $display['weight'];
$dbug['domRows'][] = $d;
$lpcnt++;
}
/* Never Reaches this */
echo '<pre>';die(print_r('Loop Finished'));
At a loss as to what's causing the failure midway through the results loop...
also..I know, I know...myql_ is depreciated, but's that's what I have to work with!
Thanks in advance for any light anyone can shed...this is really hurting the site!
EDIT: also this doesn't break all the time, so far it seems to be related somehow to the number of results...for example, if I run through a result set that has 39 rows, it will proccess all of them...and it's consitently failing at 42 rows... on my tables that have 100+ records
EDIT FINAL: Ok figured it out! Turns out we had our memory limit to low, so it was trying to allocate an illegal amount of memory! So we upped it and now it works! Also I had my error reporting in a spot where it was being conditionally turned back off by other code...that's why I wasn't seeing errors! Duh... anyway, thanks for the stabs, to those that responded Merry x-mas and all that jazz...