Faculty's server's $_post[] global variable doesnt work.Is there anybody knows the reason why is not working?
<form action="" method="POST">
<input name="asd" type="text" value="mesaj">
<input type="submit" name="eray" >
</form>
<?php
echo $_SERVER['REQUEST_METHOD'] ;
var_dump($_POST["asd"]);
echo $_POST["asd"]; ?>
I recieved null and posts in the result of this example.
I also want to share phpinfo but it s forbiden.
echo error_reporting(E_ALL); result is 22519
BTW get global is certainly working.
if
$_POST["asd"]="Working !!";
echo $_POST["asd"];
i recieved "Working !!" i dont understand. i think form doesnot submitted
Var dump is not echo-able
remove the echo and retry like this :
var_dump($_POST["asd"]);
have a good day !
The problem is
echo var_dump($_POST["asd"]);
which produces an error because
echo var_dump
is wrong/doesn't exist.
Needs to be
var_dump($_POST["asd"]);
only
Then check your php.ini for those lines:
post_max_size = 8M
variables_order = "EGPCS"
and check if those modules are running
RadCompression
RadUploadModule
you should also set this up a bit better so you dont potentially confuse yourself by looking at an empty $_POST array before you submit the form
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
print_r($_POST);
} else {
?>
<form action="" method="POST"> <input name="asd" type="text" value="mesaj">
<input type="submit" name="eray" > </form>
<?php
}
or test this
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
print_r($_REQUEST);
} else {
?>
<form action="" method="POST"> <input name="asd" type="text" value="mesaj">
<input type="submit" name="eray" > </form>
<?php
}
or this
if ($_SERVER['REQUEST_METHOD'] == 'GET'){
print_r($_GET);
print_r($_REQUEST);
} else {
?>
<form action="" method="GET"> <input name="asd" type="text" value="mesaj">
<input type="submit" name="eray" > </form>
<?php
}
?>
Related
I have this input field in a form:
<form method="post" class="tester" enctype="multipart/form-data" action="#">
<input type="number" name="test">
</form>
Whenever I try to get the input / value of the input data, filled in by my users, I can not show it (it just does not echo it). This is the code I use to echo it:
<?php
$well = $_POST['test'];
echo $well;
?>
I tried using GET as well, but nothing works.
var_dump gives me:
array(0) { }
Can you help?
Your form do not seem to have any issue even after using hash# it still process the form. Also your PHP code it's fine.
index.php
<form method="post" class="tester" enctype="multipart/form-data" action="#">
<input type="number" name="test">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$well = $_POST['test'];
echo $well;
//print_r($_POST);
}
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
Giris.php (login screen)
<html>
<form method="post" action="verify.php">
<p>Birinci Isletim Sistemi:</p> <input type="text" name="txt_biris"><br><br>
<p>Ikinci Isletim Sistemi:</p> <input type="text" name="txt_ikis"><br>
<input type="submit" value="Karşılaştır!">
</form>
</body>
</html>
Verify.php
<?php
$ad = $_POST["txt_biris"];
echo"Ad...: $ad";
$sifre = $_POST["txt_ikis"];
echo "Sifre...: $sifre";
It returns..
Error
I tried many ways, controlled variables etc. But i didnt fix it. I'm using PHP 7 on Apache 2.4.17.
Use
<?php
if(isset( $_POST["txt_biris"]))
{
$ad = $_POST["txt_biris"];
echo"Ad...: $ad";
$sifre = $_POST["txt_ikis"];
echo "Sifre...: $sifre";
}
I'm currently working through a POST method problem in PHP. I'm given the following code:
<html>
<body>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
First Name: <input type="text" name="firstname"><br>
<input type="submit">
</form>
</body>
</html>
Within the PHP tags I am supposed to write PHP code that will check if a post request method has been used to access the page, and if so, print either "correct" or "incorrect" if the first name entered is equal to "John".
Here is what I have so far:
<html>
<body>
<?
if(isset($_POST['firstname'])) {
echo 'Correct';
}
if(!isset($_POST['firstname'])) {
echo 'Incorrect';
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
First Name: <input type="text" name="firstname"><br>
<input type="submit">
</form>
</body>
</html>
I'm just not quite sure how to incorporate the "John" condition and if I am on the right track. Thanks in advance.
Just use a basic comparison operator like ==:
<html>
<body>
<?
if(isset($_POST['firstname']) && $_POST['firstname'] == 'John') {
echo 'Correct';
}
else {
echo 'Incorrect';
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
First Name: <input type="text" name="firstname"><br>
<input type="submit">
</form>
</body>
</html>
A slightly better way to only do the check if the form is submitted. You can check to see if the $_SERVER superglobal has a key REQUEST_METHOD with a value of POST.
<html>
<body>
<?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['firstname']) && $_POST['firstname'] == 'John') {
echo 'Correct';
}
else {
echo 'Incorrect';
}
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
First Name: <input type="text" name="firstname"><br>
<input type="submit">
</form>
</body>
</html>
This is very basic PHP. I suggest learning more about PHP and programming before going any further in your project.
Here is my first.php and second.php
Where i am just submitting the form itself, but i am including the second.php file which has the function get() which wil return 'ok'.
So I am calling the get() function after the form is posted.
Now how can I get the values and display it in the text fetchedvalue ?
first.php
<?php
include 'second.php';
?>
<form method="post" action="">
<input type="text" name="fetchedvalue">
<input type="submit" name="login" value="Submit">
</form>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
get();
}
?>
second.php
<?php
function get()
{
echo 'ok';
}
Note :
I have many data like that, How can I do it in a single form submit and fill all such textbox ?
try using this method:
<?php
include 'second.php';
$fvalue = '';
if(isset($_POST['fetchedvalue']))
$fvalue = $_POST['fetchedvalue'];
?>
<form method="post" action="">
<input type="text" name="fetchedvalue" value="<?=$fvalue;?>">
<input type="submit" name="login" value="Submit">
</form>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
get();
}
?>
notice that $fvalue is the variable responsible for creating value in the "fetchedvalue" input tag.. if the post is still not done, then the value would be "".
$_POST['fetchedvalue'] will contain it.
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login']))
{
echo "<pre>";
print_r($_POST); // Here you will get all posted values & then you can call get method
echo "</pre>";
get();
}
?>
You can access the variables by using $_POST like an array, so:
$fetchedValue = $_POST['fetchedvalue'];
Though, a safer approach would be the following:
<?php
include 'second.php';
$fetchedValue = filter_input(INPUT_POST, 'fetchedvalue', FILTER_SANITIZE_STRING);
?>
<form method="post" action="">
<input type="text" name="fetchedvalue" value="<?php echo $fetchedValue; ?>">
<input type="submit" name="login" value="Submit">
</form>
filter_input() will return null if no POST variable with the given name is defined, and if it is, it will apply some sanitation or validation on it. Have a look at the manual for more detailed information:
http://php.net/filter_input