Unable to send data to FPDF - html

I have a php page called page2.php which is connected to database via conectionDB.php and uploadChannel1.php to upload images. I have html page channel1.html where my form is.
But I need to send the input to FPDF to print it or save it, but this error keeps showing
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file'
I used ob_start and ob_flush and ob_clean and others but still not working I know the problem is with my php code. Please guys help me in this one.
require 'connectionDB.php';
require 'channel1.html';
require 'uploadChannel1.php';
if(isset($_POST['stdName']) && isset($_POST['secondGrand'])&& isset($_POST['grandName']) && isset($_POST['fatherAName']) && isset($_POST['motherGrand']) && isset($_POST['motherFatherName']) && isset($_POST['motherName']) && isset($_POST['subjectNum']) && isset($_POST['TotalNum'])&& isset($_POST['Avg']) && isset($_POST['birthDate']) && isset($_POST['gender']) && isset($_POST['stdType'])&& isset($_POST['jobs']) && isset($_POST['city'])&& isset($_POST['phone'])&& isset($_POST['bookDate'])&& isset($_POST['bookNo']))
{
$student=sanitizeString($_POST['stdName']);
$grand2=sanitizeString($_POST['secondGrand']);
$grand1=sanitizeString($_POST['grandName']);
$father=sanitizeString($_POST['fatherAName']);
$motherGrand=sanitizeString($_POST['motherGrand']);
$motherFather=sanitizeString($_POST['motherFatherName']);
$mother=sanitizeString($_POST['motherName']);
$subNo= sanitizeString($_POST['subjectNum']);
$Total=sanitizeString($_POST['TotalNum']);
$avg=sanitizeString($_POST['Avg']);
$graduateDate=sanitizeString($_POST['graduateYear']);
$birth=sanitizeString($_POST['birthDate']);
$gender=sanitizeString($_POST['gender']);
$job=sanitizeString($_POST['jobs']);
$stdType=sanitizeString($_POST['stdType']);
$City=sanitizeString($_POST['city']);
$tel=sanitizeString($_POST['phone']);
$bookdate=sanitizeString($_POST['bookDate']);
$bookNum=sanitizeString($_POST['bookNo']);
if(!empty($student) &&!empty($grand2) &&!empty($grand1) &&!empty($father)&&!empty($motherGrand)&&!empty($motherFather)&&!empty($mother)&&!empty($subNo)&&!empty($Total)&&!empty($avg)&&!empty($graduateDate)&&!empty($birth)&&!empty($gender)&&!empty($stdType)&&!empty($City)&&!empty($tel) && !empty($bookdate) &&!empty($bookNum) &&!empty($job))
{
session_start();
$_SESSION['stdName] =$studen ;
}
.......

Related

ES6: Tests pass in browser, fail with phantomJS, "Can't find variable: Reflect"

I am doing an ES6 rewrite for a js library.
class VerbalExpression extends RegExp {
// snipped for brevity
}
/**
* Alias for the constructor
* #return {VerbalExpression} new instance of VerbalExpression
*/
function instantiate() {
return new VerbalExpression();
}
// UMD (Universal Module Definition)
// https://github.com/umdjs/umd
if (typeof module !== 'undefined' && module.exports) { // CommonJS
module.exports = instantiate;
} else if (typeof define === 'function' && define.amd) { // AMD Module
define('VerEx', [], () => VerbalExpression);
} else { // Browser
this.VerEx = instantiate;
}
When I run the tests in my browser, they all pass.
However, when I run the tests in the terminal, I get errors.
❯ npm test
verbal-expressions#0.3.0 test /Users/shreyasminocha/dev/open source/JSVerbalExpressions
grunt test
Running "qunit:files" (qunit) task
Testing test/index.html FFFFFFFFFFFFFFFFFFFF
>> something
>> Message: Died on test #1 global code#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:7:5: Can't find variable: Reflect
>> Actual: null
>> Expected: undefined
>> ExtendableBuiltin#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:11:31
>> VerbalExpression#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:59:130
>> instantiate#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:588:32
>> somethingTest#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:8:26
...
Warning: 20 tests completed with 20 failed, 0 skipped, and 0 todo.
20 assertions (in 91ms), passed: 0, failed: 20 Use --force to continue.
Note: I am running the tests on compiled es6 code, that is, I run babel before running the tests.
I am guessing this is something to do with PhantomJS. How do I get the tests to pass in the terminal? Am I missing something? Any workarounds?
Stable PhantomJS doesn't support ES6 and is no longer in development, if possible migrate to puppeteer which is heavily inspired by PhantomJS.

PhpStorm over-indenting multi-line functions

I'm currently attempting to configure PhpStorm to produce fully-PSR-2-compliant code, however its formatter is tripping up on long lines which contain functions with multiple parameters.
When I run the formatter, it converts this:
return ($thisIsALongLine || functionCall($arg1, $arg2));
into this:
return ($thisIsALongLine || functionCall(
$arg1,
$arg2
));
However, what I want is this:
return ($thisIsALongLine || functionCall(
$arg1,
$arg2
));
Does anyone know which formatter option tells it to further indent multi-line function calls in this instance?
Note: Usually, I'd format the above as this:
return ($thisIsALongLine
|| functionCall($arg1, $arg2));
However, that just bypasses the extra indentation issue, which I'd still need to fix for other situations.
Edit: This is the state of Wrapping and Braces, as requested by #LazyOne below:
Edit 2: Examples of two different types of line which PhpStorm's formatter isn't handling correctly. (Disclaimer: This is old code from a legacy system.)
Firstly, this:
if ($validateBudget && $this->getFinancialPeriodService()->validateBudget($formModel->action, $formModel->estimatedBudget, $formModel->startDate, $formModel->endDate, $formModel->isFirstPeriod)) {
becomes this:
if ($validateBudget && $this->getFinancialPeriodService()
->validateBudget($formModel->action, $formModel->estimatedBudget,
$formModel->startDate, $formModel->endDate, $formModel->isFirstPeriod)) {
when I would expect this based on the settings above:
if ($validateBudget && $this->getFinancialPeriodService()
->validateBudget(
$formModel->action,
$formModel->estimatedBudget,
$formModel->startDate,
$formModel->endDate,
$formModel->isFirstPeriod
)
) {
Secondly, if you enable alignment on chained methods, then this:
if ($evaluation->getExpert() != NULL && ($evaluation->getExpert()->getStatusId() == Evaluation::STATUS_ASSIGNED || $evaluation->getEvaluationStage() == Evaluation::STAGE_PROPOSED && CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage1StartDate()) == false || $evaluation->getEvaluationStage() == Evaluation::STAGE_IN_PROGRESS && CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage2StartDate()) == false)) {
is reformatted to this:
if ($evaluation->getExpert() != null && ($evaluation->getExpert()
->getStatusId() == Evaluation::STATUS_ASSIGNED || $evaluation->getEvaluationStage() == Evaluation::STAGE_PROPOSED && CoreDateUtils::dateIsPast($proposal->getCalendar()
->getStage1StartDate()) == false || $evaluation->getEvaluationStage() == Evaluation::STAGE_IN_PROGRESS && CoreDateUtils::dateIsPast($proposal->getCalendar()
->getStage2StartDate()) == false)) {
when I would expect this:
if ($evaluation->getExpert() != null
&& ($evaluation->getExpert()->getStatusId() == Evaluation::STATUS_ASSIGNED
|| $evaluation->getEvaluationStage() == Evaluation::STAGE_PROPOSED
&& CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage1StartDate()) == false
|| $evaluation->getEvaluationStage() == Evaluation::STAGE_IN_PROGRESS
&& CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage2StartDate()) == false)
) {
To be honest, at this point I suspect a bug in the formatter, so will open a ticket with JetBrains, however I'll leave this open in case anyone does know why it over-/underformats things.

FUNCTION database.AddDays does not exist

I'm trying to use dbfunction from EF6 on database MySQL but I get the follow exception "FUNCTION database.DiffDays does not exist".
I used this code:
var aux = bd.Atos.Where(w => w.IdAtivo == 1 && w.IdUtilizador == idUtilizador && DbFunctions.DiffDays(DbFunctions.AddDays(w.Data, w.NumDias).Value, DateTime.Now).Value < numeroDias)
What I'm missing?

Tumblr Oauth returning 401 on API v2

I'm trying to set up an automatic tumblr post every time I add something new to my website. I'm using the following code:
$conskey = "APIKEY";
$conssec = "APISECRET";
$tumblr_blog = "blogname.tumblr.com";
$to_be_posted = "This is the text to be posted";
$oauth = new OAuth($conskey,$conssec);
$oauth->fetch("http://api.tumblr.com/v2/blog/".$tumblr_blog."/post", array('type'=>'text', 'body'=>$to_be_posted), OAUTH_HTTP_METHOD_POST);
$result = json_decode($oauth->getLastResponse());
if($result->meta->status == 200){
echo 'Success!';
}
As far as I can tell this is all formatted correctly. However this is the first time I've tried to connect up to a JSON API using Oauth so I'm not totally confident in what I'm doing.
This is the exact error I'm receiving:
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in /home/public_html/edge/tumblr.php:35 Stack trace: #0 /home/public_html/edge/tumblr.php(35): OAuth->fetch('http://api.tumb...', Array, 'POST') #1 /home/public_html/edge/index.php(95): include('/home/...') #2 {main} thrown in /home/public_html/edge/tumblr.php on line 35
Line 35 is the line beginning with $oauth->fetch.
Thanks for any help :-)
EDIT
I've solved the issue by substituting my previous code with the example on this page

parsing facebook json in rails avoid error occurred while evaluating nil.[]

I am trying to parse a json returned from facebook.
Now my idea is to get as much as detailks as possible from the facebook json.
So I use like ( assume auth is parse json from facebook)
education_array = auth['extra']['user_hash']['education']
education_array.each do |edu|
puts edu['school']['name']
puts edu['type']
puts edu['year']['name']
end
Now the problem here is that some people might have added the school name but not the year.
so obviously
edu['year']['name']
will throw error telling "error occurred while evaluating nil.[]" .
How do I avoid this ?
one way which I thought was
puts edu['year']['name']||""
but this would still throw error in case 'year' itself doesn't exist . (it would avoid error in case 'name' isn't found )
I don't want the following solution :
check if auth['extra'] exists
then check if auth['extra']['user_hash'] exists
then check if auth['extra']['user_hash']['education'] exists
then check if auth['extra']['user_hash']['education']['year']['name']
and so on..
I don't think using exception handling is a good way.
Any good way ?
Thank you
Use the && operator to check for nils.
education_array.each do |edu|
puts edu['school'] && edu['school']['name']
puts edu['type']
puts edu['year'] && edu['year']['name']
end
By way of example:
edu = { 'school' => { 'name' => 'value' } }
edu['school'] && edu['school']['name'] # => 'value'
edu = { 'school' => { } }
edu['school'] && edu['school']['name'] # => nil
edu = { 'school' => { } }
edu['school'] && edu['school']['name'] # => nil