MYSQL选择和插入

时间:2013-12-24 09:24:55

标签: php mysql database select insert

为什么不这样做!我已经把头发拉了几天试图让它起作用

 $query2 = "SELECT * FROM temporders WHERE order_id=$id";
 $result2 = mysql_query($query2);
 $row = mysql_fetch_assoc($result2);
 $osupplierid = $row['order_supplierid'];
 $odescription = $row['order_description'];
 $odate = $row['order_date'];
 $oquoteid = $row['order_quoteid'];
 $odetailid = $row['order_detailid'];
 $otype = $row['order_type'];
 $osupplierquote = $row['order_supplierquote'];
 $osupplierquotecost = $row['order_supplierquotecost']; 

 $query = "INSERT INTO orders (order_supplierid, order_description, order_date, order_quoteid, order_detailid, order_type, order_supplierquote, order_supplierquotecost )
             VALUES ($osupplierid, $odescription, $odate, $oquoteid, $odetailid, $otype, $osupplierquote, $osupplierquotecost )";

似乎没有得到行的值,因为没有任何输入,就像我用虚拟值替换它一样。

请帮忙!它的Xmas前夕我想早点完成工作。

伊恩

3 个答案:

答案 0 :(得分:0)

INSERT查询中的一些参数是String,您必须使用单引号,即使它是PHP变量。

我为字段似乎是String-type添加了引号,请检查并再试一次!

$query = "INSERT INTO orders (order_supplierid, order_description, order_date, order_quoteid, order_detailid, order_type, order_supplierquote, order_supplierquotecost )
         VALUES ($osupplierid, '$odescription', '$odate', $oquoteid, $odetailid, '$otype',     '$osupplierquote', $osupplierquotecost )";

为了进一步了解,重要的是要注意PHP mysql_ *函数已被折旧,并且您应该使用PDO或mysqli_ *函数。

我建议您使用本指南快速忽略PDO:http://www.phpeveryday.com/articles/PHP-Data-Object/PDO-Tutorial-P842.html

答案 1 :(得分:0)

试试这个:

 $query = "INSERT INTO orders (order_supplierid, order_description, order_date, order_quoteid, order_detailid, order_type, order_supplierquote, order_supplierquotecost )
             VALUES ('$osupplierid', '$odescription', '$odate', '$oquoteid', '$odetailid', '$otype', '$osupplierquote, $osupplierquotecost ')";

答案 2 :(得分:0)

 $query2 = "INSERT INTO orders (order_supplierid, order_description, order_date, order_quoteid, order_detailid, order_type, order_supplierquote, order_supplierquotecost ) SELECT order_supplierid, order_description, order_date, order_quoteid, order_detailid, order_type, order_supplierquote, order_supplierquotecost FROM temporders WHERE order_id=$id";
 $result2 = mysql_query($query2);