$_Post Doesnt Work [Undefined index] - php

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";
}

Related

PHP Submit button doesn't have any effect (PhpStorm)

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

PHP session data from form not being passed and/or not printing to screen

I am playing around with using my Raspberry Pi 3 as a web server.
I would like to learn more about processing user input through forms.
I have two files in /var/www/html, viz. form.html and form.php:
form.html:
<form action="form.php" method="post">
<input type="text" name="varname"/>
<input type="submit" name="Submit" value="Submit!" />
</form>
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['varname'] = $_POST['varname'];
}
?>
form.php:
<?php
session_start();
$var_value = htmlspecialchars($_SESSION['varname']);
echo $var_value;
?>
When I click Submit! on form.html the browser takes me to form.php which displays a blank page.
Naturally, I would like it to print $var_value to the screen.
Is there problem in my code, or could it be some other server-side issue?
Change your form.html extension to form.php,
And you may use the below code to achieve your work.
Form.php // Single page
<?php
session_start(); // Should be in first Line
if (isset($_POST['Submit'])) {
$_SESSION['varname'] = $_POST['varname'];
$var_value = htmlspecialchars($_SESSION['varname']);
echo $var_value;
}
?>
<form method="post">
<input type="text" name="varname"/>
<input type="submit" name="Submit" value="Submit!" />
</form>
?>
Otherwise: // Multiple Page
form.php
<form action="some_form.php" method="post">
<input type="text" name="varname"/>
<input type="submit" name="Submit" value="Submit!" />
</form>
some_form.php
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['varname'] = $_POST['varname'];
$var_value = htmlspecialchars($_SESSION['varname']);
echo $var_value;
}
?>

why php post global variable iis not working

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
}
?>

New to sessions in PHP

I'm trying to get to grips with sessions as it's a part of PHP I'm not very good with. Could you help me in explaining what is happening here on the two pages that I have? It is giving an undefined index and I've no idea why.
Thanks
File 1
<strong>Test Form</strong>
<form action="test2.php" method"post">
<input type="text" name="picturenum"/>
<input type="submit" name="Submit" value="Submit!" />
</form>
<?php
// starting the session
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['picturenum'] = $_POST['picturenum'];
}
?>
File 2
<?php
session_start();
echo $_SESSION['picturenum'];
?>
session_start() must go at the top of the page:
<?php
session_start();
// Opening <html>, etc goes below
?>
<strong>Test Form</strong>
<form action="test2.php" method"post">
<input type="text" name="picturenum"/>
<input type="submit" name="Submit" value="Submit!" />
</form>
<?php
if (isset($_POST['Submit'])) {
$_SESSION['picturenum'] = $_POST['picturenum'];
}
?>
This works:
Form (teste1.php)
<?php
session_start();
// Opening <html>, etc goes below
?>
<strong>Test Form</strong>
<form action="test2.php" method"post">
<input type="text" name="picturenum"/> <!-- make sure you type something here -->
<input type="submit" name="Submit" value="Submit!" />
</form>
File 2 (test2.php)
<?php
if (isset($_POST['picturenum'])) {
$_SESSION['picturenum'] = $_POST['picturenum'];
echo $_SESSION['picturenum'];
}else{
echo "something wrong with the POST";
}
?>
As far as I can see, you're starting session after the form in the first file. The rule is: you should start the session before any echo or any HTML output, even before a space. So, basically, session_start() should be your first line after <?php.
Then, how do you get to the second page? If you close the browser and then re-open it, the session of course won't persist and you'll get your undefined index.
Please comment on this if you need any further explanations.

php javascript alertbox have to click 2 times before it show

I'm doing php that is textbox a value empty it will open a alertbox (I'm using javascript in here )
this is my code
<?php
include('config.php');
if(isset($_POST['submit'])){
$username=$_POST['username'];
?>
<script>
function validate(){
if(document.forms[0].username.value==""){
window.alert("You must enter both values");
return false;
}
}
</script>
<?php
}
?>
<html>
<div><p>Member Profile</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username<br>
<input class="user" type="text" name="username" id="username" /><br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</html>
The problem is i have to click 2 times before the alert show
please help me to solve this problem
It's because the script is inside the php if(isset){} block, one click submits the form, which generates the script and then it works the second time.. try this setup instead:
<?php
include ('config.php');
if (isset($_POST['submit']))
{
$username = $_POST['username'];
}
?>
<html>
<head>
<script>
function validate () {
if (document.forms[0].username.value == "") {
window.alert("You must enter both values");
return false;
}
}
</script>
</head>
<body>
<div>
<p>
Member Profile
</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username
<br>
<input class="user" type="text" name="username" id="username" />
<br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</body>
</html>
Edit:
I've moved the script tag inside the head tag. I'm not sure if there are any implications for having the script outside but just to be sure I've moved it.
2nd Edit: (OCD is kicking in)
I've added body tags, not sure if you copied and pasted this code but it looked weird to me :)

Categories