[英]Insert user input from textbox to Database (PHP to PHPMYADMIN using mysql) Code not working for some reason
For some reason I am getting "Notice: Undefined index: adata" when I try to input data and mysql data file gets a blank space input (no text input just an empty field. 由于某些原因,当我尝试输入数据时,我得到“通知:未定义的索引:adata”,而mysql数据文件得到一个空格输入(没有文本输入,只是一个空字段。
So can you tell me guys what I did wrong, because I watched multiple tutorials, guide and read multiple posts regarding this matter yet still I could not resolve it. 因此,您能告诉我我做错了什么吗,因为我看了多个教程,指导并阅读了有关此问题的多篇文章,但仍然无法解决。
<?php
if (isset($_POST['submit']))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";
// Create connection
$dbcon = mysqli_connect($servername, $username, $password, $dbname);
mysql_select_db($db);
// Check connection
$adata = $_POST['test'];
$sql = ("INSERT INTO data (data) VALUES ('$adata')");
if (!mysqli_query($conn, $sqlinsert)) {
die('error inserting new data');
} //end of second if
} //end of if statement
?>
<html>
<head>
<meta charset="UTF-8">
<title>Insert Data Into DB</title>
</head>
<body>
<h1>Insert new data into DB</h1>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Add Data:
<input type="text" name="test">
<br />
<input type="submit" value="add new data" />
</form>
</body>
</html>
Be careful with your variables ; 注意变量;
$adata = $_POST['test'];
$sql = ("INSERT INTO data (data) VALUES ('$adata')");
if (!mysqli_query($conn, $sql)) { // it was $sqlinsert and must be $sql due your definition.
die('error inserting new data');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.