if($media=="pet")
{
if($pressure=="bar")
{
if($f_req=="ltr/m")
{
$kvreq=$flowreq/16.666666667*16.6667/(pow(($presur*1/0.98066/660*1000),0.5));
echo "<b>KV Required:- </b>$kvreq ";
?>
<br/><br/>
<?php
if($kvreq > 14 and $kvreq <= 38){
$minOrfice=10;
$n_kv=38;
$maxOrfice=7;
echo "<b>Minimum Orfice Required:- </b>$minOrfice";?>
</br></br>
<?php
$n_kv1=($n_kv/16.66667*(pow($presur*1/0.98066/660*1000,0.5)))*16.666666667;
echo "$n_kv1 <b>liter/min</b>";?>
</br></br>
<?php
echo "The Max Flow at $maxOrfice orfice";?>
</br></br>
<?php
$maxfo=((14/16.66667)*(pow(($presur*1/0.98066/660)*1000,0.5)))*16.666666667;
echo "$maxfo <b>liter/min</b>";?>
<form method="get" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input name="chkb1" type="checkbox" />
<input type="submit" value="Submit" name="chk_btn" id="chk_btn"/>
</form>
<?php
if(isset($_POST['chk_btn'])){
echo "$abc";
}
}
}
}
}
...................................................................................................................................................................................
your form method is GET while you're attemptig to get POST data
change this:
if(isset($_GET['chk_btn']))
if(isset($_POST['chk_btn'])) to if(isset($_GET['chk_btn'])) should fix the problem but OP refuse that still cannot display any text.
I suspect that upon submitting the the form again in the page it lose the value of $media, $pressure and so on there it never pass the if statements and never proceed on next process
if($media=="pet")
{
if($pressure=="bar")
{
if($f_req=="ltr/m")
{
Related
I updated the question.
Since the last code was pretty complex and even after fixing the stuff it didn't work, I executed the below simple code to check if things work. Even this code doesn't work. Whenever I click on the submit button, it again returns a 404 error.
Yes, I placed the PHP code in the body as well to check if this work but it doesn't.
<?php
if(isset($_POST['submit'])) {
echo("Done!!!!");
} else {
?>
<html>
<head>
<title>Echo results!</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="submit" type="submit" value="submit"/>
</form>
<?php
}
?>
</body>
</html>
Try giving the button_create as name of the submit button
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
if(isset($_POST['button_create'])) {
<td><input type="submit" name="button_create" id="button_create" value="Create Table!"></td>
change these lines see how you go from there
There are a couple of things wrong here, method should be POST instead of GET. The name attribute of text fields should be used when receiving the values. The submit button name should be used to check whether the button is clicked or not. See the example given below.
<?php
if (isset($_POST['submit'])) {
$ex1 = $_POST['ex1'];
$ex2 = $_POST['ex2'];
echo $ex1 . " " . $ex2;
}
?>
<form action="" method="post">
Ex1 value: <input name="ex1" type="text" />
Ex2 value: <input name="ex2" type="text" />
<input name="submit" type="submit" />
</form>
Echo results!
<?php
if(isset($_POST['submit'])) {
echo("Done!!!!");
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="submit" type="submit" value="submit"/>
</form>
<?php
}
?>
this is for your updated question
I've got a simple <form> in myFunction, as you can see here:
<?php
function myFunction()
{
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
if (isset($_POST['postform']))
{
echo "I'm working!";
}
}
?>
When I call this function, I can see the form but, when I submit it (by clicking the submit button), it disappears. How can I solve this problem?
Here is the full code:
<?php
echo "
<form method='post'>
<button name='first'>First step</button>
</form>
</div>
";
if (isset($_POST['first']))
{
myFunction();
}
?>
<?php
function myFunction()
{
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
if (isset($_POST['postform']))
{
echo "I'm working!";
}
}
?>
The issue is that $_POST superglobal is purged on new request, just like when you're navigating through pages, which is quite natural.
So, if one comes to a page with, let's say, $_POST = ['first' => ''], and then he submits a post form (or any form) ['postform' => 'send'], the resulting $_POST would be ['postform' => 'send'].
So, in your case the easiest solution would be either to follow Shailesh's answer or submit the first form with method='get' and, of course, then you'll have to change $_POST['first'] to $_GET['first'].
But a better solution would be to pass some 'step' parameter in request on each step, so you'll have <input type="hidden" name="step" value="1">. And then, depending on a step variable, do some stuff.
Also check out $_SESSION.
Cheers!
It disappears because you don't get to call the function myFunction() itself. The second form does not include the field "first".
If you want it to work "as is", include this in myFunction() code:
function myFunction()
{
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='hidden' value='send' name='first'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
if (isset($_POST['postform']))
{
echo "I'm working!";
}
}
?>
The only change is
<input type='hidden' value='send' name='first'>
which makes the form visible again. Anyway, you should rethink this whole code.
if (isset($_POST['first']))
{
myFunction();
}
Replace with:
if (isset($_POST['first']) || isset($_POST['postform']) )
{
myFunction();
}
Move your postform form processing out of the myFunction function definition and call myFunction function from there. Here's the complete code,
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
echo "
<form method='post'>
<button name='first'>First step</button>
</form>
";
if (isset($_POST['first'])){
myFunction();
}
?>
<?php
function myFunction(){
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
}
if (isset($_POST['postform'])){
myFunction();
echo "I'm working!";
}
?>
</body>
</html>
write the same as two different documents.
<html>
<body>
<form method="post" action="submit.php">
<fieldset>
<legend>Something</legend>
<input type="text" name="input">
<input type='submit' value='send' name="postform">
</fieldset>
</form>
now write the following in submit.php
<?php
$input=$_POST['input'];
if ($input!="")
{
echo "I'm working!";
}
?>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
echo "<br>You can use the following form again to enter a new name.";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>
Change this place on this code:
<?php
echo "
<form method='post'>
<button name='first'>First step</button>
</form>
</div>
";
if (isset($_POST['first']) or isset($_POST['postform']))
{
myFunction();
}
?>
I'am new to php and I have no idea why my code in php is always echoing FALSE.
I do not want to use another hidden input like:
<input type="hidden" name="storeRandVal" value="<?php echo $randomValue; ?>
to store my generated random value, and then checking if the entered value in input is equal with value that was generated and entered to hidden input. Is there any way around to do it in php also without involving cookies?
Here is my code:
<?php
$buttonPost = $_POST['button_post'];
$enteredValue = htmlspecialchars(trim($_POST['test_input_p']));
$randomValue = rand(1,100);
if(isset($buttonPost))
{
if($randomValue == $enteredValue)
{
echo "TRUE";
}
elseif($randomValue != $enteredValue)
{
echo "FALSE";
}
else
{
echo "Er__!";
}
}
?>
<html>
<head>
<meta></meta>
</head>
<body>
<form action="" method="post">
<fieldset>
<label for="test_input" id="label_input">Enter value: <?php echo $randomValue; ?></label>
<input id="test_input" name="test_input_p">
<input type="submit" id="ibutton_send" name="button_post" value="Send">
</fieldset>
</form>
</body>
</html>
Why not store the random value in a session? Re-set the session only when a form is not submitted (eg; when a user comes to this page from a different page)
As #Fred commented, you have to include the hidden input. By its nature, PHP's rand() function gives you a different answer every time you load the page.
You'll need to compare the $_POST['test_input_p'] and $_POST['storeRandVal'] values in order to confirm that the user entered the correct values.
Here's what you can do:
Store the hidden value in a variable then compare it with that value.
(Unless you will be using this for more than 2 pages, sessions are not needed, not for this since you're using your entire code inside the same page.)
<?php
$buttonPost = $_POST['button_post'];
$enteredValue = htmlspecialchars(trim($_POST['test_input_p']));
$hidden = $_POST['storeRandVal'];
$randomValue = rand(1,100);
if(isset($buttonPost))
{
if($enteredValue == $hidden)
{
echo "TRUE";
}
elseif($randomValue != $hidden)
{
echo "FALSE";
}
else
{
echo "Er__!";
}
}
?>
<html>
<head>
<meta></meta>
</head>
<body>
<form action="" method="post">
<input type="hidden" name="storeRandVal" value="<?php echo $randomValue; ?>">
<fieldset>
<label for="test_input" id="label_input">Enter value: <?php echo $randomValue; ?></label>
<input id="test_input" name="test_input_p">
<input type="submit" id="ibutton_send" name="button_post" value="Send"></input>
</fieldset>
</form>
</body>
</html>
i have a code in which i received two variable($isbn,$eno) from former page via form GET method but these two variables are not working if i am not echo out it on my page the code for the same is given below.
<?php
error_reporting(E_ALL);
require 'db/connect.php';
if(isset($_POST['generatereport']))
{
$isbn=$_GET['isbn'];
$eno=$_GET['eno'];
echo $eno; //if this is not done then i am not receiving data from database
echo $isbn; //if this is not done then i am not receiving data from database
$studentdata="select * from users where eno='$eno'";
if($studentresult=$db->query($studentdata))
{
$studentrow = $studentresult->fetch_assoc();
}
else
{
echo"fetching error";
}
$bookdata="select Lpad(isbn,'10','0') as isbn,book_name from book_data where isbn='$isbn'";
if($bookresult=$db->query($bookdata))
{
$bookrow = $bookresult->fetch_assoc();
}
else
{
echo"fetching error";
}
}
?>
<!doctype html>
<html lang='en'>
<head>
</head>
<body>
<div id='report'>
<table>
<tr><td><h3>Issue Report</h3></td></tr>
<tr><td><h4>Student details</h4></td></tr>
<tr><td>UNIQUE ID:<?php //random number here ?></td></tr>
<tr><td>Enrollment:<?php echo $eno; ?></td></tr>
<tr><td>Name:<?php echo strtoupper($studentrow['fname']);echo strtoupper( $studentrow['lname']); ?></td></tr>
<tr><td>Branch:<?php echo strtoupper($studentrow['branch']); ?></td></tr>
<tr><td>Semester:<?php echo $studentrow['sem']; ?></td></tr>
</table>
<hr/>
<table>
<tr><td><h4>Book details</h4></td></tr>
<tr><td>isbn:<?php echo $bookrow['isbn']; ?></td></tr>
<tr><td>Book Name:<?php echo strtoupper($bookrow['book_name']);?></td></tr>
</table>
<hr/>
<form action="script/issue.php?isbn=<?php echo $isbn;?>" method='post' id='report'>
<input id="btn_issue" type="button" value="Issue this Book"/>
<input id="btn_close" type="button" value="cancel"/>
</form>
</div>
</body>
</html>
You need to set attribute name to inputs in your form, after that you can access to value by GET or POST
Change form method:
<form action="script/issue.php?isbn=<?php echo $isbn;?>" method='get' id='report'>
<input name ='isbn' id="btn_issue" type="button" value="Issue this Book"/>
<input name ='eno' id="btn_close" type="button" value="cancel"/>
</form>
Or get your variables from post, like:
$isbn=$_POST['isbn'];
$eno=$_POST['eno'];
change your from method to get
<form action="script/issue.php?isbn=<?php echo $isbn;?>" method='get' id='report'>
or you can use $_REQUEST in php which can read either get or post
If you use method="POST", it meant you should use $_POST for your next process. Can use $_REQUEST also. But I think $_POST is more specifics for method POST. Please read the documentation of PHP about form method again.
I want to display messages at top ids "MessageError" and "MessageOK" according to POST results. Example:
<p id="MessageError"></p>
<p id="MessageOK"></p>
<form name="Form" method="post" action="<?php $_SERVER[ 'PHP_SELF' ]; ?>" enctype="multipart/form-data" accept-charset="UTF-8" id="Form">
<input type="text" name="test" value="" /> <input type="submit" name="Submit" value="" />
</form>
<?php
if ( isset ( $POST[ 'Submit' ] ) ) {
if ( $_POST[ 'test' ] ) {
// Echo message at "MessageOK
}
else {
// "Echo message at "MessageError"
}
}
?>
Any help will be appreciated.
Thank you.
Move the code above your form to print the error message above your form. Also your paragraph tags can be created on the fly, to avoid waste:
<?php
if(isset($_POST['submit'])){
if($_POST['test'])echo("<p id='MessageOk'>There was an Error</p>");
else echo("<p id='MessageError'>There was no error</p>");
}
?>
If you are dead set on adding content to pre-created divs using PHP, can I suggest creating an input using PHP eg:
<?php
$test = $_POST['test'];
echo("<input type='hidden' id='test' value='$test' />");
?>
And then using JavaScript to append data:
if(document.getElementById('test').value){
document.getElementById('MessageOk').innerHTML = 'No Error';
}
else{
document.getElementById('MessageError').innerHTML = 'Error ??';
}
move your php code over the form, assign the echo message to a variable and use <?php echo $variable; ?> to print the message at the appropriate place...
Make sure you include the _ on your post variable.
$_POST[]