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 4 years ago.
Improve this question
I have text box:
Size of array:
After this i have button Show array:
<html>
<body>
<form name="form" method="post">
Size of array: <input type="number"value="5" name="size", min="2", max="10">
<input type="submit" name="Send" value="Show array"></span></p>
</form>
</body>
</html>
<?php
if(isset($_POST['Send']))
{
//what must be here?
}
?>
but i don't know, how to generate random numbers from digits, which is entered in text box, e.g. if text box contains 8, then generates 8 random numbers from 2 until 10..can u help please ?
Edit new version i think is what you want??
$numb=range(2,10);
shuffle($numb);
$output = array_slice($numb, 0, $_POST['guess']);
echo implode(',',$output);
range() to make an array of the numbers you want to use (2-10). shuffle randomises them, array_slice() picks the number of elements according to the form input. implode for display.
Old version:
<html>
<body>
<form name="form" method="post">
Size of array: <input name="guess" type="number" value="5" name="size", min="2", max="10">
<input type="submit" name="Send" value="Show array"></span></p>
</form>
</body>
</html>
<?php
if(isset($_POST['Send']))
{
for ($i = 0; $i < $_POST['guess']; $i ++) {
$random[] = rand(2, 10);
}
echo implode(',', $random);
}
?>
the for loop is running the number of times the user selected, and the rand is picking the numbers, implode is gluing the numbers together for output
Related
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
Hello i want to check if the textarea isnt empty and i still can´t get the echo that i want even when the textarea isnt empty and input is set
here is my code:
<form method="post" action="">
<input type="text" name="jmeno"/>
<textarea name="textarea" id="textarea" rows="5" cols="40"></textarea>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['jmeno']) AND !empty($_POST['textarea'])){
echo "dokončeno";
}
?>
How about this:
if (!is_null($_POST['jmeno']) && strlen(trim($_POST['jmeno'])) > 0) {
echo "dokončeno";
}
As far as I understand you want your code to check if the submit button is pressed and the textarea isn't empty. I would say the code is:
if(isset($_POST['jmeno'])){
if(strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
}
OR simply:
if(isset($_POST['jmeno']) && strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
if (isset($_POST['jmeno']) && strlen(trim($_POST['textarea']))>0)
{
echo "dokončeno";
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I can make a simple set of IF statements to find whether a number is either a composite or a prime (even though I think a function would be better suited).
However, I can't echo out either statement below when I try to up-my-game and use post.
There are no syntax errors here, just flawed logic. Problem is, where is the flaw??
Thanks for any advice.
<form>
<form name="PrimeCalculator" method="post" action="">
<input type="text" name="input"> Enter any number to see if it's a Prime or Composite<br />
<input type="submit" name="submit" value="Calculate">
</form>
<?PHP
if($_POST['submit'] == "Calculate"){
$num=$_POST["input"];
for ($i = 2; $i <= $num-1; $i++) {
if ($num % $i == 0) {
$value= True;
}
}
if ($value) {
echo 'The Number '. $num . ' Is A Composite';
} else {
echo 'The Number '. $num . ' Is A Prime';
}
}
?>
Your error actually is in the html, remove the first <form> tag and it should work, though your code is throwing
E_NOTICE : type 8 -- Undefined variable: value -- at line 14
when entering a prime number as $value isn't set then.
You can use
if (isset($value) && $value)
for the check instead.
<form name="PrimeCalculator" method="post" action="">
<input type="text" name="input"> Enter any number to see if it's a Prime or Composite<br />
<input type="submit" name="submit" value="Calculate">
</form>
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 8 years ago.
Improve this question
How do I Get This HTML 5 Form To Give PHP The Input Data Then Display It On The Screen. I want to collect data in a form. Convert it into a php variable and then echo it out in a way that I can read it.
<form>
First name:<br>
<input type="text" name="name">
</form>
<body>
<pre>
<?php
$taco = htmlspecialchars($_POST["name"]) . '!';
$taco = $_POST;
echo $taco;
?>
</pre>
</body
</html>
How about the following:
<?php
if($_POST) { // check if the page is posted not with a $_GET
foreach($_POST as $field => $value) { // Foreach field
$value = strip_tags($value); // Strip html tags (you can add more)
echo 'Field: '.$field.' has value: '.$value.'<br>'; // output
}
}
?>
<form action="" method="post">
First name: <input type="text" name="first_name">
<input type="submit" value="Display">
</form>
Just put it all in one php file. You can add as many fields as you want.
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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post">
Text that needs to be processed
<input type="text" id="text" name="t">
<input type="submit" id ="order" name="order">
<input type="text" name="credit" value="100" readonly="true" id="credit"/>
</form>
<?php
if(isset($_POST['order']))
{
print_r($_POST['t']);
}
?>
</body>
</html>
How do I manipulate the value of "credit" on click of submit (i want to be able to set the value of the credit field to the $_POST['t] value
After seeing your comment, this is easily achievable by doing this:
<input type="text" name="credit" value="<?php echo (isset($_POST['order'])) ? $_POST['t'] : '100';?>" readonly="true"id="credit"/>
Using the shorthand ternary operator (?:) (A shorter if/else)
You're basically saying
echo (IF POST[order] IS SET) ? SHOW POST[t] : OTHERWISE SHOW 100;
Pseudo code above
Edit: in relation to your next comment
if(isset($_POST['order'])) {
$t = $_POST['t'];
$v = $_POST['credit'];
$total = ($t - $v);
}
and further on (in the form)
<input type="text" name="credit" value="<?php echo (isset($total)) ? $total : '100';?>" readonly="true"id="credit"/>
Untested Pseudo code above. You'll want to make sure that the numbers don't decrease below 0 possibly?
Another edit based on your comment here
You're on the right path, you just have to set up the conditions:
if(isset($_POST['order'])) {
$t = $_POST['bet'];
$v = $_POST['credit'];
if($_POST['bet'] > $_POST['credit']) {
$total = $v;
echo "<h1>YOUR BET IS TOO HIGH MAN</h1>";
} else {
$total = ($t - $v);
}
}
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 9 years ago.
Improve this question
I'm trying already for two hours to understand what am I doing wrong and I can't figure it out:
My HTML code:
<form action="php/images.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" value="on" id="file">
<input type="submit" name="submit" value="Submit">
</form>
My PHP:
if ( isset($_POST['image'])
&& $_POST['image']=="on")
{
imageUpload();
}
When I removed the if in the PHP file and immediately entered the inner function imageUpload() I've been able to upload the image, why is the variable name I pass using post isn't working?!
Your upload data will be in $_FILES array:
<?php print_r($_FILES['image']); ?>
So something like this:
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
imageUpload();
}
}
?>
browse button lets you make an array and can be obtain via $_FILES['image'];.Similarly $_FILES also gives an array(size etc).Try var_dump($_FILES); to get the values.