This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
i am building a multi step login page like that of gmail,
i want the email address the the user typed in to be stored in a global variable so i can echo it in the next step of the form i have been trying but can't figure it out, have seen many error, when i change the code i get a different one the new one i have now is (Notice: Undefined index: email in C:\xampp\htdocs\xxxxx\index.php on line 3)
this is the form
<form action="" method="post" class="form-login">
<div class="step-login step-one">
<input type="text" class="email"/>
<input type="button" class="btn next-step" value="next">
</div>
</form>
this is the php code that i am trying to use and store the input, i think this is where the problem is
<?php
$emails = $_POST['email'];
if(isset($_POST['next'])){
$GLOBALS['email'] = $_GET['email'];
}
?>
this is the code where i am trying to echo the varible
<div class="data-user-find">
<p class="user-email"><?php echo $GLOBALS['email']; ?></p>
</div>
Please guys help me
The "value" of your button is "next", but your button isn't called "next", it should be <button name="next" value="next" type="submit">
Then your error would go away. Also, you define an $email variable outside of your if-clause, please put it inside your if clause, so your code would be this:
<?php if(isset($_POST["next"]) {
$email = $_POST["email"]; (DONT FORGET TO GIVE YOUR MAIL INPUT THE 'name="mail"' TAG)
$GLOBALS["email"] = $email;
} ?>
Related
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 2 years ago.
<?php include 'connection.php'; ?>
<?php
if (isset($_GET['consultation']))
{
echo "Consultation Details";
$no=$_GET['consultation'];
?>
<form class="" method="get">
<textarea name="details" rows="8" cols="80" placeholder="enter consultation details"></textarea><br>
<button type="submit" name="c">submit</button>
</form>
<?php
if (isset($_GET['details'])) {
$details=$_GET['details'];
}
//$details= $_GET['details'];
$insertQuery="INSERT INTO redo (consultation) VALUES ($details) WHERE no=$no;";
$insert = mysqli_query($conn,$insertQuery);
if ($insert) {
echo "recorded";
?>
Back to Total Patients
Back to Registration
<?php
}
else {
echo "record couldnt be inserted";
}
}
?>
No $_GET['details'], you sure you're using a GET method in the form? Change $_GET['details'] to $_REQUEST['details'].
To be exact, this one fails:
if (isset($_GET['details'])) {
$details=$_GET['details'];
}
I mean, the if condition is not met, so $details is not defined, as you don't define it anywhere in the code outside that if.
Other solution would be adding:
$details = '';
in front of that if.
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
My Code Looks Like:
<?php
echo "
<form action='form.php'>
<input type='text' name='value'>
<input type='submit'>
</form>
";
?>
And form.php is
<?php
echo $_POST['value'];
?>
Error Code is:
Notice: Undefined index: value in C:\xampp\htdocs\dynamic\form.php on line 2
Is it possible to get the value of field created using echo command?I don't want to use database,jQuery etc.
You need to set the form method to post
<?php
echo "
<form action='form.php' method='post'>
<input type='text' name='value'>
<input type='submit'>
</form>
";
?>
you are missing method="post" in form tag
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
I have a text-area, in which I need some text.
I simply need to get that text to be echoed out with PHP, while on the same page
This is my code so far:
<body>
<br>
<h1>Charles Dickens</h1>
<form action="Charles Dickens.php" method="GET">
<hr/>
<textarea rows="20" cols="100" name="textTest">This a is the text Testing area.</textarea>
<hr/>
</form>
<br>
<br>
<?php
$textTest = $_GET['textTest'];
echo $textTest;
?>
</body>
for some reason it's give me an "undefined error", though the variable is defined:
textTest is undefined.
I suggest you to change your file name as well:
it should be without space or with hyphens
here you can like this, but you need to submit a form:
<?php
if(isset($_GET["textTest"]){
echo $_GET["textTest"];
}
?>
If you don't want to submit form try it:
<script>
$('#text-id').keypress(function() {
var value = this.value;
console.log(value);
});
</script>
you have to check if the get variable is still defined:
<?php
if(isset($_GET["textTest"]){
echo $_GET["textTest"];
}
?>
or add ?textTest=the%20text to the uri ;)
I cannot add a comment for this...
Try doing
var_dump($_GET['textTest'])
Also add what Ahmad Hassan said, as before you submit the form the varible is undefined
if(isset($_GET['textTest'])) { echo $_GET['textTest'] }
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 6 years ago.
I have this issue that my form obviously doesn't send data with POST method but it sends it with GET method.
Here is my HTML code of the form
<form action="action.php" method="POST">
<input type="text" name="text">
<input type="submit" value="send">
</form>
and here is the php code in the action page
if($_SERVER['REQUEST_METHOD'] == 'POST'){
echo $_POST['text'];
var_dump($_POST);
}
if(isset($_POST['text'])){
echo "ok";
}else{
echo "no";
}
when I submit the form I get this error for output
Notice: Undefined index: text in F:\test\action.php on line 9
array(0) { } no
but when I send data with GET method it works correctly without any problem.
I think the problem is for phpstorm because it runs correctly in the xampp server. and the considerable thing is when I run it in mozila or IE it says page not found but xampp is okay.
Try using isset with your input like so:
You have to add name="something" for the isset to pick up that you have clicked it.
<?php
if (isset($_POST['sub']))
{
echo $_POST['text'];
}
?>
<form action="" method="post">
<input type="text" name="text">
<input type="submit" name="sub" value="Submit">
</form
I can only assume that the output you are seeing is before you submit the form. When you submit it, you should check for POST and not for post:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
^^^^ here
echo $_POST['text'];
}
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
Every time I hit submit button after selecting an image will face the problem "Notice: Undefined index: profile_picture in C:\wamp\www\Test\testImage.php on line 5", and the page print the text not selected which must be display if image is not selected.
The index is defined, but why it is behave like this, please help with your suggestions
<?php
$photo = "";
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$photo = trim(stripslashes($_POST["profile_picture"]));
if($photo != '')
{
//$photo = trim(stripslashes($_POST["profile_picture"]));
header("Location: success.php");
}
else{
echo 'not selected';
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form name="signup_form" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<input type="file" class="profile_picture" id="profile_picture" name="profile_picture"> </br>
<input type="submit" name="submit_btn" id="submit_btn" class="submit_btn" value="sign up">
</form>
</body>
</html>
Files are not posted over $_POST.
They are posted with $_FILES array.
Reference