2015-04-24 33 views
1

我试图将数据发布到两个数据库分别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 ; 



-- 
+0

注意:'mysql_ *'功能被取消,并将从PHP的未来版本中删除。你不应该使用它们来编写新代码,而应该使用'mysqli_ *'或者PDO。 –

回答

1

使用此查询而不是第二个查询。

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

降序被resevered ...和MySQL是depricated ... 使用

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