我想获得一个表格来将数据输入到我的“mysql数据库”中,但是我收到一条错误消息,并且它每次加载页面时都会输入一个空白数据。向一个mysql数据库输入数据的HTML表格
这里是我的代码:
Name:
// This is the connection to my database
$con = mysql_connect('127.0.0.1', 'shane', 'diamond89');
if (!$con){
die('Could not Connect: ' . mysql_error());
}
// This creates my table layout
echo "
ID | Name | Delete |
---|
// This selects which database i want to connect to
$selected = mysql_select_db("shane",$con);
if (!$con){
die("Could not select examples");
}
// This inserts new information to the Database
$query = "INSERT INTO test1 VALUES('id', '$name')";
$result = mysql_query($query);
if ($result){
echo("Input data is Successful");
}else{
echo("Input data failed");
}
// This chooses which results i want to select from
$result = mysql_query("SELECT `id`, `name` FROM `test1` WHERE 1");
// This outputs the information into my table
while ($row = mysql_fetch_array($result))
{
echo "
";echo "
" . $row['id'] . "";echo "
" . $row['name'] . "";echo "
" . "[D]" . "";echo "
";}
echo "
";// This closes my connection
mysql_close($con);
?>
以下是错误消息:
尖叫(!):错误抑制忽略 通知(!):未定义的变量:名称在C:\ WAMP \在线路36上 调用栈
时间记忆功能位置
1 0.0006 250360 WWW \ sql_table.php {主}()。 \ sql_table.php:0
+0
你确定'name'存在于你的表中吗? –
+0
您正在使用[an **过时的**数据库API](http://stackoverflow.com/q/12859942/19068)并应使用[现代替换](http://php.net/manual/en/ mysqlinfo.api.choosing.php)。 –
+0
尝试通过在页面的第一行添加' –