PHP中插入数据时未定义的变量错误

时间:2018-08-25 05:43:10

标签: php mysql

the     Notice: Undefined variable: id in C:\xampp\htdocs\sql\connect_db.php on line 21
    Notice: Undefined variable: name in C:\xampp\htdocs\sql\connect_db.php on line 21
    Notice: Undefined variable: productdes in C:\xampp\htdocs\sql\connect_db.php on line 21
    Notice: Undefined variable: price in C:\xampp\htdocs\sql\connect_db.php on line 21

使用HTML表单将数据插入数据库时​​,出现上述错误。 不在我的数据库中插入任何数据

<?php


$link=mysqli_connect("localhost","root","");
if($link->connect_error){
    die("Connection failed: " . $link->connect_error);

}
echo("Successfully ..!");
$cb = mysqli_select_db($link, "demo"); // connect database 
if (!$cb) {
    die("Database selection failed: " . mysqli_error($link));
}
echo(" <br> Succesfully connect Database ..!");

if(isset($_POST['id'])) {$id = $_POST['id'];}  
if(isset($_POST['product'])){ $product = $_POST['product']; }
if(isset($_POST['product_dec'])){ $productdes = $_POST['product_dec']; }
if(isset($_POST['price'])){ $price = $_POST['price']; }
if(isset($_POST['submit'])){ $submit = $_POST['submit']; }
$sql_query = "INSERT INTO plist (id,product,product_dec,price) VALUES('$id','$product','$productdes','$price')";
$inset=mysqli_query($sql_query,$link);

?>

0 个答案:

没有答案