如何修复插入问题到数据库?

时间:2017-04-09 09:57:37

标签: php mysql

我有3个表涉及此交易,项目,交易和销售。 问题仅出现在销售表中,因为如果要插入到现场客户的值是数字,它只会保存到表销售中,但如果要插入的值是客户的名称则不保存。它似乎只接受数字,但我的客户数据类型是文本,它必须接受字符,如我们的名字。抱歉,我的英语不好,但我希望你能帮助我,代码和表格在下面

<?php

	include ('dbconnect.php');
	$itemcode = $_POST['itemcode'];
	$cusname = $_POST['cusname'];
	$price = $_POST['price'];
	$qty = $_POST['qty'];
	$left = $_POST['left'];	
	$newstock = ($left - $qty);
	$amount = $_POST['amount'];
	$tobepaid = ($price * $qty);
	$change = ($amount - $tobepaid);

	if ($amount<$tobepaid){
			echo "<script language='javascript'>
					alert('The amount tendered is insufecient for the item');
					document.location.href='stockout.php';
				</script>";	
	}
	else{
	mysql_query("update item set 
		qty = '$newstock'
		where itemcode = '$itemcode'");



    $result = mysql_query("INSERT INTO `transaction` (`transtype`, `itemcode`, `prevstock`, `qty1`, `currentstock`) VALUES ('stockout',$itemcode,$left,$qty,$newstock)");
	$result = mysql_query("INSERT INTO `sales` (`itemcode`,`customer`, `qty2`,`tobepaid`, `amount`,`change`) VALUES ($itemcode,$cusname,$qty,$tobepaid,$amount,$change);");


	echo "<script language='javascript'>
					alert('Updated $cusname');
					document.location.href='stockout.php';
				</script>";	
	mysql_close($con);
}
?>

mysql> select * from sales;
+---------------------+----------+----------+------+----------+--------+--------+
| datetime            | itemcode | customer | qty2 | tobepaid | amount | change |
+---------------------+----------+----------+------+----------+--------+--------+
| 2017-04-09 17:00:07 | 2901     | 12       | 1    | 15000    | 15000  | 0      |
+---------------------+----------+----------+------+----------+--------+--------+
1 row in set (0.00 sec)

mysql> select * from transaction;
+---------------------+-----------+----------+-----------+------+--------------+
| datetime            | transtype | itemcode | prevstock | qty1 | currentstock |
+---------------------+-----------+----------+-----------+------+--------------+
| 2017-04-09 16:11:31 | stockout  | 2901     | 19        | 1    | 18           |
| 2017-04-09 16:12:53 | stockout  | 2901     | 18        | 1    | 17           |
| 2017-04-09 16:13:42 | stockout  | 2901     | 17        | 2    | 15           |
| 2017-04-09 16:14:41 | stockout  | 4526     | 16        | 1    | 15           |
| 2017-04-09 16:16:26 | stockout  | 26350    | 32        | 1    | 31           |
| 2017-04-09 16:18:18 | stockout  | 26350    | 31        | 1    | 30           |
| 2017-04-09 17:00:07 | stockout  | 2901     | 15        | 1    | 14           |
| 2017-04-09 17:01:14 | stockout  | 2901     | 14        | 1    | 13           |
| 2017-04-09 17:03:39 | stockout  | 33321    | 27        | 1    | 26           |
| 2017-04-09 17:07:37 | stockout  | 12000    | 24        | 1    | 23           |
| 2017-04-09 17:08:08 | stockout  | 2901     | 13        | 1    | 12           |
+---------------------+-----------+----------+-----------+------+--------------+
11 rows in set (0.00 sec)

mysql> select * from item;
+----------+-------------------------+-----+-------+
| itemcode | item_abb                | qty | price |
+----------+-------------------------+-----+-------+
| 2901     | King Bed                |  12 | 15000 |
| 26350    | King Size Dinning Table |  30 | 15000 |
| 33321    | Sofa                    |  26 | 4500  |
| 4526     | chandelier              |  15 | 5000  |
| 12000    | Swinging Chair          |  23 | 3500  |
+----------+-------------------------+-----+-------+

this the form where to get the values

0 个答案:

没有答案
相关问题