Why does my PHP Calculator doesn't evaluate a error message after typing letters into number fields? - calculator

I tried to code a simple calculator in PHP, and if I type in numbers everything ist perfect, but if I try to type in letters or words into the number fields, there should be shown a error message, that one of the numbers isn't a numeric sign. But for some reason it is not working. I showed my PHP Code in the follwing picture I will show my html-Code which is named Taschenrechner.php and my php-Code which is named Taschenrechner2.php.
Thank you very much for your time and help
best wishes
Here is my Code of the PHP-Form1
<?php include("kopf.inc.php");?>
And here is my PHP Code from the Evaluation of the typed in numbers
<?php include("kopf.inc.php");?>
Here are two pictures of the failure text
Picture of my PHP-form output
And Picture of the PHP output

I Cant see much of your code besides include statements.
of you Declare a variable in php you dont assign the datatype. The Datatype is assigned when you assign a Value to a variable.
<?php
$Variable = 1; //makes $Variable a Integer
echo $Variable . "\r\n";
echo gettype ($Variable) . "\r\n";
$Variable = 'nun ist $Variable ein String'; //changes the datatype from Integer to String.
echo $Variable . "\r\n";
echo gettype ($Variable) . "\r\n";
$StringOne = 'S1';
$StringTwo = 'S2';
$ResultTwoStrings = 'ResultTwoStrings';
$StringOne + $StringTwo = $ResultTwoStrings;
echo $ResultTwoStrings;
?>
This will Result in the fallowing output:
1
integer
nun ist $Variable ein String
string
Warning: A non-numeric value encountered in ./Playground/file0.php on line 13
Warning: A non-numeric value encountered in ./Playground/file0.php on line 13
ResultTwoStrings
I am not sure why you dont get an error message.

Good evening everybody, after I lacked a little bit in motivaton during the last few months I noticed, that I forgot posting my code. A little bit embarassing. But now, I had a spelling mistake with my variables so they were not the same but thank you everybody

Related

Trouble converting string to int and using it on a for loop

I'm a shell script beginner here, and I'm having some trouble with something - oddly specific - that I haven't found help for.
For sheer fun, I tried to code something that you feed a string into and that runs that through yes and lolcat, for cool rainbow text.
Something like this.
The code is pretty straightforward, and uses $((...)) to convert a string (the number of times the user wants its string to be repeated) to an integer.
Anyways, here's the code. I've tried moving the point in the script where the string is converted, but nothing.
echo Lolcat_repeater: A wonderful tool that does absolutely nothing.
echo [I] Input a string to lol:
echo [P] :: && read input
echo [I] Times to repeat [ENTER for endless]:
echo [P] :: && read repeats
$repeats=$(($repeats))
if [ $repeats == "" ]
then
yes $input | lolcat
else
for ((i=1; i<=$repeats; i++))
do
echo $input | lolcat
done
fi
This error always pops up:
./lolcat_repeater.sh: 11: Syntax error: Bad for loop variable
And, judging by how the code doesn't execute yes $input | lolcat when I just hit ENTER, I clearly messed something up in the conditional.
I know I probably sound stupid right now, but any help will be appreciated.
Thanks!

Error in Linkdatagen : Use of uninitiated value $chr in concatenation (.) or string

Hi I was trying to use linkdatagen, which is a perl based tool. It requires a vcf file (using mpileup from SAMtools) and a hapmap annotation file (provided). I have followed the instructions but the moment I use the perl script provided, I get this error.
The codes I used are:
samtools mpileup -d10000 -q13 -Q13 -gf hg19.fa -l annotHapMap2U.txt samplex.bam | bcftools view -cg -t0.5 - > samplex.HM.vcf
Perl vcf2linkdatagen.pl -variantCaller mpileup -annotfile annotHapMap2U.txt -pop CEU -mindepth 10 -missingness 0 samplex.HM.vcf > samplex.brlmm
Use of uninitiated value $chr in concatenation (.) or string at vcf2linkdatagentest.pl line 487, <IN> line 1.... it goes on and on.. I have mailed the authors, and haven't heard from them yet. Can anyone here please help me? What am I doing wrong?
The perl script is :
http://bioinf.wehi.edu.au/software/linkdatagen/vcf2linkdatagen.pl
The HapMap file can be downloaded from the website mentioned below.
http://bioinf.wehi.edu.au/software/linkdatagen/
Thanks so much
Ignoring lines starting with #, vcf2linkdatagen.pl expects the first field of the first line of the VCF to contain something of the form "chrsomething", and your file doesn't meet that expectation. Examples from a comment in the code:
chr1 888659 . T C 226 . DP=26;AF1=1;CI95=1,1;DP4=0,0,9,17;MQ=49;FQ=-81 GT:PL:GQ 1/1:234,78,0:99
chr1 990380 . C . 44.4 . DP=13;AF1=7.924e-09;CI95=1.5,0;DP4=3,10,0,0;MQ=49;FQ=-42 PL 0
The warning means that a variable used in a string is not initialized (undefined). It is an indication that something might be wrong. The line in question can be traced to this statement
my $chr = $1 if ($tmp[0] =~ /chr([\S]+)/);
It is bad practice to use postfix if statements on a my statement.
As ikegami notes a workaround for this might be
my ($chr) = $tmp[0] =~ /chr([\S])/;
But since the match failed, it will likely return the same error. The only way to solve is to know more about the purpose of this variable, if the error should be fatal or not. The author has not handled this case, so we do not know.
If you want to know more about the problem, you might add a debug line such as this:
warn "'chr' value not found in the string '$tmp[0]'" unless defined $chr;
Typically, an error like this occurs when someone gives input to a program that the author did not expect. So if you see which lines give this warning, you might find out what to do about it.

php gettext include string with phpcode

i'm trying to use gettext to translate the string in my site
gettext doesn't have problem detecting strings such as
<? echo _("Donations"); ?>
or
<? echo _("Donate to this site");?>
but obviously, usually we'll use codes like this in our site
<? echo _("$siteName was developed with one thing in mind"); ?>
Of course in the website, the $siteName is displayed correctly as
My Website was developed with one thing in mind
if we put
$siteName = "My Website";
previously.
My problem is, i'm using poedit to extract all the strings in my codes that needs to be translated, and it seems poedit doesn't extract all string with php codes like I described above. So how do I get poedit extract strings with php code inside it too? Or is there any other tools I should use?
One possibility is to use sprintf. Just make sure you keep the percent (%) in the poedit string!
echo sprintf( _("This %s can be translated "), 'string');
Or when using multiple variables
echo vsprintf( _("This %s can be %s"), ['string', 'translated']);

mysqli commands using '

I have been following a tutorial to better understand php's oop, but have come across a stumbling block, im not sure if it's an oop thing or something that i just haven't come across in the procedural way of doing things, i'm pretty new and trying to learn a lot quickly. I like to know what's happening before moving on.
Below is the code, which I understand apart from why under users_username i need ', and another ', before selecting users_email? At first I thought it was a way of separating them so as a test I removed them and was returned the error: Trying to get property of non-object. So I am guessing by removing them i am somehow stopping the name being created as an object? or am I way off the mark.
"SELECT CONCAT(users_username,
',
',
users_email)
AS name,
DATE_FORMAT(users_joined, '%M %d, %Y') AS dr
FROM users
ORDER BY users_joined
ASC";
$r = $mySqli->query($q);//run the query
$num = $r->num_rows;//assign the number of rows
if($num > 0){//if there are members in the database
echo '<p>There are currently ' . $num . ' members registered.</p>' . "\n";
while($row = $r->fetch_object()){
echo $row->name . ' ' . $row->dr . "<br/>";
}
}
Apologies if this has been asked many times before but I didn't know how to search this question.
What CONCAT(users_username, ',',users_email) is doing is taking the users_username appending a comma and then appending the users_email. So if users_username is bob and users_email is bob#example.com that will return "bob,bob#example.com".
If you remove the single quotes then it is just CONCAT(users_username,,,users_email) and PHP might not like that there is nothing between the commas. In this case the query may be failing and returning NULL for $row. So when you do $row->name it tries to get the name property of $row but since $row is NULL it doesn't have any properties.

Spreadsheet::WriteExcel something wrong with write_formula

I'm trying to write an formula using WriteExcel
=SUMIF(J3:J54;"=xxx";H3:H54)
but that code:
$sheet->write_formula($row+1, 0, "=SUMIF(J" . ($row-($row-3)) . ":J" . ($row-2) . ";\"=xxx\";H" . ($row-($row-3)) . ":H" . ($row-2) . ")");
ends with
Unknown defined name SUMIF in formula at test.pl line 196
But when I print out that formula (using print) I got exactly the same string as wanted one (calculations on $row are good)
I'm pretty sure this code should work
You need to us the US style union operator "," instead of the European style ";":
=SUMIF(J3:J54,"=xxx",H3:H54)
If you modifiy your formula string to replace ; with , it will work. I tested it.