check array for limitations [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am accepting form submissions.
To prevent spoofing of the form I am using php isnumeric to verify that the posted values contain only numeric values.
I would like to check also:
1) that the posted values array contains max 1000 values (because no user would buy more than 1000 items!)
2) that the size of a single array key is composed of max 20 numbers (bigint unsigned max length)
how do I achieve this?

Point 1:
if (count($posted_values) <= 1000)
{
...
}
else
echo "Error";
Point 2:
Did you mean PHP_INT_MAX ?
If yes, just do:
foreach($posted_values as $value)
and then check that $value is less or equal than PHP_INT_MAX.

Related

SUM OF NUMBERS IN WHILE LOOP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I'm trying to find the sum of numbers by querying a database using PHP and MYSQL. I need a while loop or any other solution that can add numbers that are >= 40 from a sequence of numbers. I'm only able to make the query but don't know how to go about the rest.
$selectMARK="SELECT mark FROM resultstbl WHERE mark >= 40";
$queryMARK=mysqli_query($dbCon, $select);
$sum=0;
while($rowz=mysqli_fetch_assoc($queryMARK))
{
// need some code to add the numbers here
}
You maybe need an
$iterator = 0;
outside the loop, that you can increment inside of it.
$sum += $rowz[$iterator];
$iterator++:
Then do your condition around it by checking $rowz[$iterator] <= 40

how to return an INTEGER_ARRAY [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
Given an integer, n, determine the following:
How many 1-bits are in its binary representation?
The number n’s binary representation has k significant bits indexed from 1 to k. What are the respective positions of each 1-bit, in ascending order?
The function is expected to return an INTEGER_ARRAY
The function accepts INTEGER n as parameter

How to sum two rows input file numbers to one row output file (PHP) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
Input data:
In the input file INPUT.TXT there are two non-negative integers are given by two rows and the numbers are less than 10 powered by 100.
Output data:
in the OUTPUT.TXT file is needed to return sum of the numbers to one row, without initial zeros
Example:
#
input.txt
output.txt
1
3
7
4
Check it , It will help you
$data = explode("\n", file_get_contents('INPUT.TXT'));
$sum = intval($data[0])+intval($data[1]);
echo $sum;
file_put_contents('OUTPUT.TXT', $sum);

change specific values of array in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
<?php
$x=6;
$y=9;
$time = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
for ($i=$x;$i<=count($y);$i++)
{
If($x!=$y)
{
$time[$i]=1;
}
}
?>
Depending on the value of x and y,the values in array should change.
In this example... array[5] until array[8] should be value 1.
The value of x and y will not same.
Not a very good question, but I'm a little bored. So for fun:
array_splice($time, $x-1, $y-$x-1, array_fill(0, $y-$x+1, 1));
Not exactly sure of the logic using 6 and 9 and array[5] until array[8] is, but adjust the numbers to fit the range.

Can't insert numbers with decimal [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i have a problem with inserting decimal numbers. The code is a "earning system" that calculate salary. The query insert 2 instead of 2.50.
My code looks like this:
$quantity = "1";
$earned = $quantity * '2.5'; //type = double
//.. query update to table etc..
Mysql:
`earned` decimal(10,2) NOT NULL DEFAULT '0.00'
I tried to echo $earned, and it says 2,5 instead of 2.5 would that be the problem??
Solution:
I removed my setlocale
use number type values instead of strings,try this..
$quantity = 1;
$earned = $quantity * 2.5;
This is a long shot, since you didn't post your actual mysql query, but most likely the 2.5 value is converted in 2,5 by your locale settings.
The easiest solution is to quote all the values you are putting inside your query, so you won't have any side-effects

Categories