This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
PHP & Case Sensitivity [duplicate]
(3 answers)
Closed 5 years ago.
I have a problem with isset. What I want is some echos after getting, checking and initialising the values from isset. it doesn't work. I don't see any reason behind this. It only refreshes the page after submitting the form.
Below is the code
<?php
if (isset($_post['contact_name'] ) && isset($_post['contact_email']) && isset($_post['contact_text']))
{
echo $contact_name = $_post["contact_name"];
echo $contact_email = $_post['contact_email'];
echo $contact_text = $_post['contact_text'];
//!empty($_post['contact_name'])
//echo 'no value submit';
if(!empty($contact_name) && !empty($contact_email) && !empty($contact_text))
{
echo 'ok';
}
else
{
echo 'all fildes required !!!!!!!!!!!!!';
}
}
?>
<html>
<form action="index.php" method="post">
name : <br> <input type="text" name="contact_name" ><br><br>
Email address : <br> <input type="text" name= "contact_email "><br><br>
Message :<br><textarea name="contact_text" rows="6" cols="30" type="text" ></textarea><br><br>
<input type="submit" value="send">
</form>
</html>
You need to use this;
<?php
if (isset($_POST['contact_name'] ) && isset($_POST['contact_email']) && isset($_POST['contact_text']))
{
...
Use $_POST instead of $_post. Hope this will work.
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 8 months ago.
I have a html/php code as shown below in the file abc.php in which at Line#A, I am getting the following error:
Notice: Undefined variable: world in abc.php on line#A
html/php code (abc.php) :
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$world = $_POST['world'];
}
<form method="post" action="abc.php?id=<?= $id; ?>">
<input type="hidden" name="world" value="<?= $world; ?>"/> //line#A
</form>
This is what I have tried but it doesn't seem to work:
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$world = isset($_POST['world']);
}
The $world variable will only be defined if page served via POST method.
So, what you need is define it before the condition:
$world = "";
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$world = $_POST['world'];
}
<form method="post" action="abc.php?id=<?= $id; ?>">
<input type="hidden" name="world" value="<?= $world; ?>"/> //line#A
</form>
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 5 years ago.
I don't wanna use an action page. I wanna post on the same page.
These are my codes. But there is an error called "Undefined index: baslik on line 5 and aciklama on line 6
<?php
include("baglan.php");
$site_basligi = mysqli_real_escape_string($conn, $_POST['baslik']);
$site_aciklamasi = mysqli_real_escape_string($conn, $_POST['aciklama']);
$ayarsql = "UPDATE ayar SET baslik='$site_basligi', aciklama='$site_aciklamasi' WHERE durum='1'";
if($conn->query($ayarsql)){
echo "Güncelleme başarılı";
}
?>
<form action="" method="post">
Site Başlığı: <input type="text" name="baslik" ><br><br>
Açıklama: <input type="text" name="aciklama"><br><br>
<input type="submit">
</form>
<?php
include("baglan.php");
// check for post request here
if(isset($_POST['baslik']) && $_POST['baslik'] != "") {
$site_basligi = mysqli_real_escape_string($conn, $_POST['baslik']);
$site_aciklamasi = mysqli_real_escape_string($conn, $_POST['aciklama']);
$ayarsql = "UPDATE ayar SET baslik='$site_basligi', aciklama='$site_aciklamasi' WHERE durum='1'";
if($conn->query($ayarsql)){
echo "Güncelleme başarılı";
}
}
?>
<form action="" method="post">
Site Başlığı: <input type="text" name="baslik" ><br><br>
Açıklama: <input type="text" name="aciklama"><br><br>
<input type="submit">
</form>
You are not checking if the POST data actually exists, so when you first load the page there is no $_POST
do something like
if (isset($_POST)){
//your php code here
}
I can see the form IS submitting to the same page.
You just should wrap the PHP code in if condition
<?php
include("baglan.php");
if(!empty($_POST['baslik'])) { // This is the new if condition
$site_basligi = mysqli_real_escape_string($conn, $_POST['baslik'] );
$site_aciklamasi = mysqli_real_escape_string($conn, $_POST['aciklama']);
$ayarsql = "UPDATE ayar SET baslik='$site_basligi', aciklama='$site_aciklamasi' WHERE durum='1'";
if($conn->query($ayarsql)) {
echo "Güncelleme başarılı";
}
}
?>
<form action="" method="post">
Site Başlığı: <input type="text" name="baslik" ><br><br>
Açıklama: <input type="text" name="aciklama"><br><br>
<input type="submit">
</form>
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
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
undefined index [closed]
(2 answers)
Closed 9 years ago.
These are my codes And i'm getting error
Notice: Undefined index: command in E:\xampp\htdocs\Shop_cart\products.php on line 17
Javascript:
<script language="javascript">
function addtocart(pid){
document.form1.productid.value=pid;
document.form1.command.value='add';
document.form1.submit();
}
</script>
HTML Code:
<form name="form1" action="">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
<input type="button" value="Add to Cart" onclick="addtocart(1)" />
</form>
PHP Code:
if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
$pid=$_REQUEST['productid'];
addtocart($pid,1);
header("location:shoppingcart.php");
exit();
In your PHP code add isset check to the condition:
if ( isset($_REQUEST['command']) && $_REQUEST['command'] == 'add' && $_REQUEST['productid']>0 ) {}
Change
if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
to
if(isset($_REQUEST['command']) && $_REQUEST['command']=='add' && $_REQUEST['productid']>0){
Same to other answer but I would literally proceed something like this for security purposes and better layout of my code.
//Check if request has been made
if (isset($_REQUEST['command'])){
//proceed for checking
if($_REQUEST['command'] == 'add' && $_REQUEST['productid']>0 )
{
//Your code here
}
}else{
//redirect or whatsoever
}