-2

I am trying to submit a form with two conditions regulated by a checkbox. If the second condition is true, I get a warning message--Undefined array key "outside" in C:\xampp\htdocs\Taxi. I tried the following code:

if (isset($_POST['assign'])){
    $tid=addslashes($_POST['tid']);
    require 'dbconnect.php';
    if(addslashes($_POST['outside']))
    {
        $outside=addslashes($_POST['outside']);
        $outinv=addslashes($_POST['inv']);
        $sql = "UPDATE trips SET inventory='$outside',cardetails='$inv' WHERE id='$tid'";
        $stmt = $con->prepare($sql);
        $stmt->execute();
    }
    else if(!addslashes($_POST['outside'])){
        $asn=addslashes($_POST['asn']);
        echo $asn;
    }
}
brombeer
  • 8,716
  • 5
  • 21
  • 27
  • 1
    Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Progman Feb 13 '22 at 17:49
  • FYI, `addslashes` has absolutely no business whatsoever being in that code. – CBroe Feb 14 '22 at 08:34

1 Answers1

0

Maybe you want this.

if (isset($_POST['assign'])){

$tid=addslashes($_POST['tid']);

 require 'dbconnect.php';


if(isset($_POST['outside']))
{
$outside=addslashes($_POST['outside']);
 $outinv=addslashes($_POST['inv']);


 $sql = "UPDATE trips SET inventory='$outside',cardetails='$inv' WHERE id='$tid'";
$stmt = $con->prepare($sql); $stmt->execute();

 }
else {
$asn=addslashes($_POST['asn']);
echo $asn;

}
}