将数据发布到两个数据库表中

时间:2015-04-24 09:05:08

标签: php mysql

我正在尝试将数据发布到两个数据库add_productledger中,但我一直收到以下错误消息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, amount)values('mnbvx', 'opening stock', '5')' at line 1

以下是我的PHP代码:

   <?php
include ('session.php');
if($_GET["name"] && $_GET["opening"]&& $_GET["re"])
{

$servername="localhost";
$username="root";
$db="multiple";
$pass="";
mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$name=$_GET["name"];
$op=$_GET["opening"];
$re=$_GET["re"];
mysql_query("insert into add_product (product, opening, current,     reorder)values('$name', '$op', '$op', '$re')");

mysql_query("insert into ledger (product, desc, amount)values('$name',   'opening stock', '$op')")or die(mysql_error());


print "<h4>product added to database</h4>";
print "<p><a href='add_pdt.html'>add another?</a></p>";
print "<a href='index_admin.php'>home</a>";
}
else{
print "please fill all fields correctly";
print " ";
print "<p><a href='add_pdt.html'>back</a></p>";
print "<p><a href='index_admin.php'>home</a></p>";

}
?>



below is - Table structure for table `ledger`
CREATE TABLE IF NOT EXISTS `ledger` (
`product` varchar(60) NOT NULL,
`desc` varchar(60) NOT NULL,
`amount` varchar(15) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


below --
-- Table structure for table `add_product`

CREATE TABLE IF NOT EXISTS `add_product` (
`product` varchar(30) NOT NULL,
`id` int(30) NOT NULL,
`opening` int(100) NOT NULL,
`current` int(100) NOT NULL,
`reorder` int(6) NOT NULL,
`updateon` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=93 ;



--

3 个答案:

答案 0 :(得分:1)

使用此查询代替第二个查询。

mysql_query("insert into ledger (`product`, `desc`, `amount`)values('$name',   'opening stock', '$op')")or die(mysql_error());

答案 1 :(得分:0)

DESCreserved keyword。要么围绕它使用反引号:

`desc`

或重命名。

答案 2 :(得分:0)

desc被重新分配......并且mysql被删除了...... 使用

$con = ('localhoat','root','','database_name');
mysqli_query($con,"insert into ledger (`product`, `desc`, `amount`)values('$name','opening stock', '$op')")or die(mysql_error()");