ramiwahdan
-
Posts
114 -
Joined
-
Last visited
Posts posted by ramiwahdan
-
-
6 hours ago, ataboy said:
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}$conn->close();
?>Hi,
you need to change $conn to $link
you have:
if ($conn->query($sql) === TRUE) {
and have:
$conn->close();
change them to
if ($link->query($sql) === TRUE) {
and
$link->close();
-
1 hour ago, Barand said:
The whole content of your web page changes based on choices. The link is just another bit of output.
Here's an idea - try thinking.
Hi,
So I put the link in my original php file and when i am directed to the fpdf page i get the first error as i am walking my way through...
First my code:
<?php require('fpdf/fpdf.php'); include('dbcon.php'); // ADD YOUR OWN PDO CONNECTION CODE // $servername = "localhost"; $username = "???"; $password = "???"; $db = "timeclock"; $conn = new PDO("mysql:host=$servername;dbname=$db", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); class attendPDF extends FPDF { protected $today; protected $headbase; protected $db; protected $sid; protected $name; protected $sdate; protected $edate; //constructor public function __construct($db, $oracleid, $sdate, $edate) { parent::__construct(); $this->today = date('jS M Y'); $this->db = $db; $this->sid = $oracleid; $this->sdate = new DateTime($sdate); $this->edate = new DateTime($edate); $res = $this->db->prepare("SELECT staffname FROM staff WHERE oracleid = ? "); $res->execute( [ $oracleid ] ); $this->name = $res->fetchColumn(); }
and here is the error:
Fatal error: Uncaught Error: Call to a member function prepare() on string in C:\xampp\htdocs\AttendanceSystem\login\fpdf.php:36 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\fpdf.php(148): attendPDF->__construct('timeclock', '533349', '2020-03-01', '2020-03-31') #1 {main} thrown in C:\xampp\htdocs\AttendanceSystem\login\fpdf.php on line 36
I confirm all info is correct so why there is an error
-
11 hours ago, Barand said:
Looks like you have a bit of reading to do regarding the use of FPDF. You can't just call the cell() function and output a PHP table into it.
Don't mix the screen output code with FPDF code. Put the FPDF into a separate script. Display the web page and put a link to the pdf page EG
<a href='attendance_pdf.php?oracleid=533349&sdate=2020-03-01&edate=2020-03-05'>Print version</a>
First, thanks for the big help. So i will keep my original untouched or i will only take the code you gave me? If i keep the original, what changes i need to do to that? your screenshots shows both attendance and absent tables, is if from the file you gave me? If i need to add the link you gave me to my original php file, it changes based on choices, how to get that? Lastly, I used to get the dates from a form, in your file, how are we getting these dates?
-
55 minutes ago, Barand said:
https://css-tricks.com/almanac/properties/p/page-break/
Or write a custom script using FPDF or similar so you have complete control
i am trying to use FPDF as you mention it but i am able to find out the problem.
and here is what i tried:
require('fpdf/fpdf.php'); $pdf = new FPDF(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Absent Report'); $pdf->SetFont('Arial','',8);
and i am adding the pages at the end after displaying my data
\\ code before foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <p>Absent Report:</p> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> <?php $pdf->AddPage(); $pdf->Cell(40,10,$tdata); $pdf->Output(); ?> </table> <a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html>
I get this error
Fatal error : Uncaught Exception: FPDF error: No page has been added yet in C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php:271 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php(1447): FPDF->Error('No page has bee...') #1 C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php(643): FPDF->_out('BT 2.83 822.92 ...') #2 C:\xampp\htdocs\AttendanceSystem\login\singlereportidfinal.php(22): FPDF->Cell(40, 10, 'Absent Report') #3 {main} thrown in C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php on line 271
I am trying to put the last table (absents) in new page
-
4 minutes ago, ginerjm said:
What is a "second page"? Is it another web page being sent to the client? I don't know how you define "page" since there are no real "pages" on web displays.
screenshot, the data split to second page, instead i want the absent table to all move to second page in the printer
-
I have print page using window.print in the body tag at the beginning of php file and i am trying to make the rest of the code as second page, the last table will be on the second page. it is not working.
code:
<b>Absent Report:</b> <table style ="page-break-before: always;" border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> <a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html>
why it is not working?
-
6 minutes ago, ramiwahdan said:
i am sorry that you got upset but in my company they might search for someone for a week as example so they dont want to look the whole month.
i got it when you said the word date and realized i have start date. now, can i add to that code an end date?
$month = $sdate1; $start_date = new DateTime("$month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime());
can i have end date since it is taking start date?
-
5 minutes ago, Barand said:
What do think the date table is for?
But OK, have it your way. Bye.
i am sorry that you got upset but in my company they might search for someone for a week as example so they dont want to look the whole month.
-
22 minutes ago, Barand said:
$sdate1 and $edate1 would define the date range to put in the date table.
no, i want to use them so i can pull out records from db only between the chosen dates.
-
25 minutes ago, Barand said:
You would need to test for the oracleid in the staff table IE
WHERE s.oracleid = ? AND a.oracleid IS NULL
since it is doing a LEFT JOIN the attendance_records table (alias a) to find missing dates.
i need to add between dates from a form to add to where clause and I tried this but it will return nothing, the table is empty again
code:
WHERE a.oracleid IS NULL and s.oracleid = '$userid' and DATE(a.ClockingOutDate) >= $sdate1 and DATE(a.ClockingOutDate) <= $edate1
sdate1 and edate1 are variables taken from form fields in the page of type date.
-
4 minutes ago, gizmola said:
Most likely you simply need to pass the oracleid into the query as a parameter. Assuming this is PDO...
$stmt = $conn->prepare("SELECT s.oracleid , s.staffname , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid = ? ORDER BY s.oracleid, d.date "); $stmt->execute(array($oracleid)); $result = $stmt->fetchAll();
here is the whole code to see where is my mistake!
why i am getting error
$conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.staffname , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid = $userid ORDER BY s.oracleid, d.date "); $result = $conn->fetchAll(); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table>
please advise
-
I have this code that will get the absent dates for all employees, how can i make it for one specific employee using oracle id?
code:
$res = $conn->query("SELECT s.oracleid , s.staffname , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date ");
the records i am concerned about is for the attendance records table, I have oracle id in that table.
-
18 minutes ago, Barand said:
You need to set a few attributes when you create your PDO connection.
$conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
Then you will be notified of any SQL problems.
Did you read my edit to earlier post about subtracting 1 day from the dates (to get Sun - Thu working week)?
Thank you very much sir, really great help and promise i will do something about it. Great
-
10 minutes ago, Barand said:
I haven't a clue.
Which foreach() is it complaining about?
$tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html>
if i add this i get the error, i noticed if i create normal table i am getting results but it also includes the non absent days. can you check where is the mistake?
full code
<?php $month = 'March'; $start_date = new DateTime("first monday of $month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime()); $servername = "localhost"; $username = "???"; $password = "???"; $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password); // create temporary date table $conn->exec("CREATE TEMPORARY TABLE date (date date not null primary key)"); // populate it foreach ($period as $d) { $dates[] = "('{$d->format('Y-m-d')}')" ; } $conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.name , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date "); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html>
what about this, why is it null?
WHERE a.oracleid IS NULL
-
42 minutes ago, Barand said:
I thought you might be able manage that bit. Here's a fuller version
<?php $month = 'March'; $start_date = new DateTime("first monday of $month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime()); // create temporary date table $conn->exec("CREATE TEMPORARY TABLE date (date date not null primary key)"); // populate it foreach ($period as $d) { $dates[] = "('{$d->format('Y-m-d')}')" ; } $conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.name , date_format(date, '%W %d/%m/%Y') as absent FROM attendance_staff s CROSS JOIN date d LEFT JOIN attendance_record a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date "); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html>
i just ran this code, i am getting error
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\AttendanceSystem\try.php
why?
-
6 minutes ago, Barand said:
I thought you might be able manage that bit. Here's a fuller version
<?php $month = 'March'; $start_date = new DateTime("first monday of $month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime()); // create temporary date table $conn->exec("CREATE TEMPORARY TABLE date (date date not null primary key)"); // populate it foreach ($period as $d) { $dates[] = "('{$d->format('Y-m-d')}')" ; } $conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.name , date_format(date, '%W %d/%m/%Y') as absent FROM attendance_staff s CROSS JOIN date d LEFT JOIN attendance_record a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date "); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html>
Thanks,
one more thing, instead of first Monday how to make it from first day, also in my country the holiday is Friday and Saturday not Saturday and Sunday, how to change that?
-
Just now, Barand said:
As it says on the tin - it's a temporary table. It lasts until the connection closes, which is whe when the script terminates,
i did understand this but why i am getting empty page, i did what you did. how to show the data?
-
2 hours ago, Barand said:
// create temporary date table $conn->exec("CREATE TEMPORARY TABLE date (date date not null primary key)");
this is not created in the db? i am missing anything?
-
40 minutes ago, ramiwahdan said:
Hi,
I have db table that records the days (Sunday, Monday...) when the employee login to the system. Say that the employee logged in on Monday then Logged in on Wednesday so this means he was absent on Tuesday. I calculated the number of days to get the answer 2 (between Wednesday and Monday before logging in on Wednesday) how to get the name of the missing day "Tuesday"?
code:
$curdate = date("Y-m-d"); $currday = date('l'); $lastdate = $row['indate']; $lastdayin = $row['lastdayin']; if ($lastdate !=Null) { $misseddates = strtotime($curdate) - strtotime($lastdate); $misseddates = $misseddates / 86400; echo $misseddates; $misseddays = strtotime($lastdayin) - strtotime($currday); $misseddays = $misseddays / 86400; echo $misseddays; }
I tried to get the name of day in the last step but it only calculates 5 in numbers how to get the name. I want the answer to be "Tuesday" as of the example.
Thanks.
OK here is what i need as output if possible:
last login: Monday 23-3-2020 today's date: Wednesday 25-3-2020 add record to db that Tuesday 24-3-2020 is absent
the first 2 i am getting from records in db, how i can get the information like last line "Tuesday 24-3-2020"? then i can add to db.
-
Hi,
I have db table that records the days (Sunday, Monday...) when the employee login to the system. Say that the employee logged in on Monday then Logged in on Wednesday so this means he was absent on Tuesday. I calculated the number of days to get the answer 2 (between Wednesday and Monday before logging in on Wednesday) how to get the name of the missing day "Tuesday"?
code:
$curdate = date("Y-m-d"); $currday = date('l'); $lastdate = $row['indate']; $lastdayin = $row['lastdayin']; if ($lastdate !=Null) { $misseddates = strtotime($curdate) - strtotime($lastdate); $misseddates = $misseddates / 86400; echo $misseddates; $misseddays = strtotime($lastdayin) - strtotime($currday); $misseddays = $misseddays / 86400; echo $misseddays; }
I tried to get the name of day in the last step but it only calculates 5 in numbers how to get the name. I want the answer to be "Tuesday" as of the example.
Thanks.
-
10 minutes ago, gw1500se said:
I think if you echo $todate you will get your answer.
6 minutes ago, Phi11W said:"Danger, Will Robinson!"
Your suffering from [Evil] Type Coercion here.
$_POST variables are all Strings.
Feeding them into the date() function forces PHP to parse and convert the given String value into a Date value, which can have some very confusing consequences.More importantly, though, your quoting is messing things up.
PHP doesn't understand the "smart"/sloping quotes that seem to have their way into your Post, so I'm assuming you're not really using those. 🙂
Double-quoted strings have variables inside them expanded. Single-quoted string do not.
$x = '10' ; if ( '10' === "$x" ) => true because $x is expanded into the value '10' if ( '10' === '$x' ) => false because '10' != '$x'
So, your first call to the date() function really is trying to make a date out of the String value '$fromdate'. Lose the quotes to pass the value of the $fromdate variable.
You should never trust User input, so you should be explicitly parsing the POST'ed String values to make sure they represent sensible Date values, and then pass the resulting Date values into the date() function.
Regards,
Phill W.thanks for the help, here is what i tried:
$fromdate = $_POST['sdate']; $todaten = $_POST['edate']; $fromdate2 = date("d-m-Y",$fromdate); $todate2 = date("d-m-Y",$todate);
now getting new error:
Notice : A non well formed numeric value encountered in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php on line 107
please advise? Since POST is getting a string how to convert to date?
-
I am trying to get the full date from form field using the date function and post method.
$fromdate = $_POST[‘sdate’]; $todate = $_POST[‘edate’]; $fromday = date(‘F j, Y, g:i a’,’$fromdate’); $today1 = date(‘F j, Y, g:i a’,’$todate’);
When trying to print i get the right format but i get extra information not sure from where? I am getting the date from the form fields of type date.
Code Output:
March 19, 2020, 4:16 pm,$31202019pm31Asia/Dubai
why i am getting the second part!
-
I had to re-create all tables again.
-
Hi,
I have select statement that will take data from form and add it to select statement but i get this error:
Fatal error : Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':startdate and DATE(ClockingOutDate) <= :enddate ORDER BY o' at line 16 in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php:62 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php(62): PDO->query('SELECT oracleid...') #1 {main} thrown in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php on line 62
this is the code:
<?Php include('session.php');?> <html> <head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> </head> <body> <Center> <h2>Please enter start date and end date:</h2> </center> <form action="#" method="post"> <center> <h5>Start Date:<input type="date" name="sdate" placeholder = "Start Date" required="required"></input> End Date:<input type="date" name="edate" placeholder = "End Date" required="required"></input> <input type="submit" name="saveit" value="Generate"></input></h5> </center> </form> <div class="container"> <div class="row"> <div class="col m-auto"> <div class="card mt-5"> <table class="table table-bordered"> <tr> <input type="button" onClick="window.print()" value="Print The Report"/> <td>OracleID</td> <td>Name</td> <td>Designation</td> <td>Clocking In Time</td> <td>Clocking Out Time</td> <td>Duration</td> </tr> <?php if (isset($_POST['saveit'])) { $servername = "localhost"; $username = "rwahdan"; $password = "fatima2010"; $sdate1 = $_POST['sdate']; $edate1 = $_POST['edate']; $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $res = $conn->query("SELECT oracleid , name , des , clockingindate , clockingoutdate , timediff(clockingoutdate, clockingindate) as duration , total FROM attendance_records JOIN ( SELECT oracleid , sec_to_time(sum(timestampdiff(SECOND, clockingindate, clockingoutdate))) as total FROM attendance_records where isdone =-1 GROUP BY oracleid ) tots USING (oracleid) where isdone =-1 and DATE(ClockingOutDate) >= :startdate and DATE(ClockingOutDate) <= :enddate ORDER BY oracleid, clockingindate "); $prepared=$conn->prepare($res); // bind parameters with placeholders $prepared->bindParam(':startdate',$_POST['sdate']); $prepared->bindParam(':enddate',$_POST['edate']); // execute the query $prepared->execute(); // fetch results $results=$prepared->fetchAll(); // this will return an array containing all of the rows in the result set // check for errors if ($prepared->errorCode()!=0) { die(print_r($prepared->errorInfo())); } ?>
problem with where clause conditions but don't know how to deal with this issue.
page break for table
in PHP Coding Help
Posted
I am using your code, i passed link from my old page to new page that has your code, the line that makes the select statement is having that error. for fpdf i am using your code with page named fpdf.php