your question already answered here "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP
additionally :
no it's not dumb, but to be honest it's a beginner common mistakes
you almost do it this right, by doing
if(isset($_POST['country'])){ $country = $_POST['country']; }
however it will not completely solve your problem.
there are two ways to solve it, depend on your preferences.
first solutions
is you can save it using default value
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "titan";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//default values, coz you will used it whetter isset true or not in line 25
$country = '';
$name = '';
$tel = '';
if(isset($_POST['country'])){ $country = $_POST['country']; }
if(isset($_POST['name'])){ $name = $_POST['name']; }
if(isset($_POST['tel'])){ $tel = $_POST['tel']; } //you should use $tel instead $name
// use escaped double quote
$sql = "INSERT INTO orders (country, name, tel)
VALUES (\"$country\", \"$name\", \"$tel\")";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
alternatively, the second solution
is to only insert if all the data valid
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "titan";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//only insert if all data valid!
if(isset($_POST['country']) && isset($_POST['name']) && isset($_POST['tel'])) {
$country = $_POST['country']; }
$name = $_POST['name']; }
$tel = $_POST['tel']; } //you should use $tel instead $name
$sql = "INSERT INTO orders (country, name, tel)
VALUES (\"$country\", \"$name\", \"$tel\")";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
} else {
echo "Error: data not valid";
}
$conn->close();
hopefully it can help you in some way,
have a nice day!