我正在创建一个数据库和表。这是数据库和表创建的代码:
<?php
//error_reporting(E_ALL);
//connect to mysql
$db = mysql_connect('127.0.0.1', 'root', '') or die ('Unable to Connect.Check your connection parameters');
//create the main database if it doesn't already exists
$query = 'CREATE DATABASE stock1';
mysql_query($query, $db) or die (mysql_error($db));
//make sure our recently created db is the active one
mysql_select_db('stock1', $db) or die (mysql_error($db));
//create the products table
$query = 'CREATE TABLE products1(
product_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
product_name VARCHAR(40) NOT NULL,
product_stock SMALLINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY(product_id)
)';
echo "Success";
?>
在此之后,我创建一个接受 2 个输入的文件,然后将此数据传输到一个 php 文件。这是HTML:
<html>
<head>
<title>Inventory - Backend</title>
</head>
<body>
<form action="addproducts.php" method="post">
<table>
<tr>
<td>Product Name : </td>
<td><input type="text" name="pname"/></td>
</tr>
<tr>
<td>Product Quantity : </td>
<td><input type="text" name="productq"/></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><input type="submit" name="Add Product"/></td>
</tr>
</table>
</form>
</body>
</html>
这是支持的:
<?php
$db = mysql_connect('127.0.0.1', 'root', '') or die ('Unable to Connect.Check your connection parameters');
mysql_select_db('stock1', $db) or die (mysql_error($db));
$productname=$_POST['pname'];
$productquantity=$_POST['productq'];
$query = 'INSERT INTO products1
(product_id, product_name, product_stock)
VALUES
(NULL, "' . $productname . '", ' . $productquantity . ')';
mysql_query($query, $db) or die (mysql_error($db));
echo "Product Added";
?>
但是,当我尝试运行此脚本时,出现此错误:
Table 'stock1.products1' doesn't exist
谁能告诉我为什么会出现这个错误?我该如何解决?