Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-1个表单,2个表-Can';t在表1中插入数据_Php_Mysql_Forms_Html Table - Fatal编程技术网

PHP-1个表单,2个表-Can';t在表1中插入数据

PHP-1个表单,2个表-Can';t在表1中插入数据,php,mysql,forms,html-table,Php,Mysql,Forms,Html Table,我正在尝试制作一个发票系统,从教程中添加行,并将数据正确插入tbl_orderdetail,但我无法将数据插入tbl_order 以下是两个MYSQL表: CREATE TABLE IF NOT EXISTS `tbl_order` ( `id` int(11) NOT NULL AUTO_INCREMENT, `re_name` varchar(255) DEFAULT NULL, `location` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`

我正在尝试制作一个发票系统,从教程中添加行,并将数据正确插入tbl_orderdetail,但我无法将数据插入tbl_order

以下是两个MYSQL表:

CREATE TABLE IF NOT EXISTS `tbl_order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`re_name` varchar(255) DEFAULT NULL,
`location` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

这是我的连接代码:

<?php
$cn = mysql_connect('localhost','root','');
if($cn)
{
mysql_select_db('mydb',$cn);
}

if(isset($_POST['submit']))
$re_name = $_POST['re_name'];
$location = $_POST['location'];
{
mysql_query ("INSERT INTO tbl_order(re_name,location)        VALUES('{$_POST['re_name']}','{$_POST['location']}')");
$id = mysql_insert_id();
for($i = 0 ;$i < count($_POST['productname']);$i++)
{
    mysql_query("INSERT INTO tbl_orderdetail 
                SET order_id        = '{$id}', 
                    product_name    = '{$_POST['productname'][$i]}', 
                    quantity        = '{$_POST['quantity'][$i]}', 
                    price           = '{$_POST['price'][$i]}', 
                    discount        = '{$_POST['discount'][$i]}', 
                    amount          = '{$_POST['amount'][$i]}'
                ");
}
}
?>

谢谢大家对我的帮助。
我放弃了tbl_订单,创建了一个名为“奥卡门”的新订单

以下是有效的php代码:

if(isset($_POST['submit']))
{
$razao     = $_POST["razao"];
$local      = $_POST["local"];
$condicao     = $_POST["condicao"];
$estado         = $_POST["estado"];
$material       = $_POST["material"];
$obs        = $_POST["obs"];
mysql_query
("INSERT INTO orcamen ( id , razao , local , condicao , estado , material , obs ) 
        VALUES ( NULL , '$razao', '$local', '$condicao', '$estado', $material', '$obs')");
$id = mysql_insert_id();
for($i = 0 ;$i < count($_POST['productname']);$i++)
{
    mysql_query("INSERT INTO tbl_orderdetail 
                SET order_id        = '{$id}', 
                    product_name    = '{$_POST['productname'][$i]}', 
                    quantity        = '{$_POST['quantity'][$i]}', 
                    price           = '{$_POST['price'][$i]}', 
                    discount        = '{$_POST['discount'][$i]}', 
                    amount          = '{$_POST['amount'][$i]}'
                ");
}
}
if(isset($\u POST['submit']))
{
$razao=$_POST[“razao”];
$local=$_POST[“local”];
$condico=$_POST[“condico”];
$estado=$_POST[“estado”];
$material=$_POST[“material”];
$obs=$_POST[“obs”];
mysql\u查询
(“插入奥卡门(id、razao、当地、康迪科、estado、材料、obs)
值(NULL、$razao'、$local'、$condicao'、$estado'、$material'、$obs');
$id=mysql_insert_id();
对于($i=0;$i
发生了哪些错误?你还需要格式化你的代码。没有写的错误,但是唯一能得到我输入的表是tbl_orderdetail。表tbl_顺序始终为空。是否启用了错误报告?是的,@script47正在尝试使用Chrome Logger进行调试。您可以在chrome控制台上打印值
<form  action="" method="post"> 
<div class="box-body">
            <div class="form-group">
                ReceptName
                <input type="text" name="re_name" id="re_name" class="form-control">
            </div>
            <div class="form-group">
                Location
                <input type="text" name="location" id="location" class="form-control">
            </div>
            <input type="submit" class="btn btn-primary" name="submit" id="submit" value="Save Record">
    </div>

        <table class="table table-bordered table-hover">
            <thead>
                <th>No</th>
                <th>ProductName</th>
                <th>Quantity</th>
                <th>Price</th>
                <th>Discount</th>
                <th>Amount</th>
                <th><input type="button" value="+" id="add" class="btn btn-primary"></th>
            </thead>
            <tbody class="detail">
                <tr>
                    <td class="no">1</td>
                    <td><input type="text" class="form-control productname" name="productname[]"></td>
                    <td><input type="text" class="form-control quantity" name="quantity[]"></td>
                    <td><input type="text" class="form-control price" name="price[]"></td>
                    <td><input type="text" class="form-control discount" name="discount[]"></td>
                    <td><input type="text" class="form-control amount" name="amount[]"></td>
                    <td><a href="#" class="remove">Delete</td>
                </tr>
            </tbody>

            <tfoot>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th style="text-align:center;" class="total">0</th>
            </tfoot>
        </table>
    </div>      
          </div><!-- /.box -->
          </form> 
        </div><!--/.col (left) -->
if(isset($_POST['submit']))
{
$razao     = $_POST["razao"];
$local      = $_POST["local"];
$condicao     = $_POST["condicao"];
$estado         = $_POST["estado"];
$material       = $_POST["material"];
$obs        = $_POST["obs"];
mysql_query
("INSERT INTO orcamen ( id , razao , local , condicao , estado , material , obs ) 
        VALUES ( NULL , '$razao', '$local', '$condicao', '$estado', $material', '$obs')");
$id = mysql_insert_id();
for($i = 0 ;$i < count($_POST['productname']);$i++)
{
    mysql_query("INSERT INTO tbl_orderdetail 
                SET order_id        = '{$id}', 
                    product_name    = '{$_POST['productname'][$i]}', 
                    quantity        = '{$_POST['quantity'][$i]}', 
                    price           = '{$_POST['price'][$i]}', 
                    discount        = '{$_POST['discount'][$i]}', 
                    amount          = '{$_POST['amount'][$i]}'
                ");
}
}