【发布时间】:2021-01-20 06:38:46
【问题描述】:
我有 2 个表,一个有数据,另一个在同一个数据库中是空白的。
a)- 表“cusrec”是主表,其中包含数据。
b)- 表“订单”为空,我想在其中插入数据。
我试图从“cusrec”表中获取数据并将其插入“order”,当我回显时,它显示了“cusrec”表的数据,但它没有插入“order”表。两个表都在同一个数据库中。
代码是:
<?php
mysql_connect("localhost","root","");
mysql_select_db('dobhighat');
if(isset($_GET['search'])){
$srch = $_GET['srch'];
$que=mysql_query("select * from cusrec where custid='$srch' OR mobile='$srch'");
$ftch=mysql_fetch_array($que);
$scustid=$ftch['custid'];
$sname=$ftch['name'];
$smobile=$ftch['mobile'];
$totcloth=$ftch['clothpackage'];
if(isset($_POST['confirm']))
{
$ordernum=$_REQUEST['ordernum'];
$orderdate=date('d/m/y');
$ordercloth=$_REQUEST['ordercloth'];
$clothrem=$totcloth-$ordercloth;
$abc=mysql_query("insert into order(custid,name,mobile,totcloth,orderno,orderdate,ordercloth,clothrem)values('$scustid','$sname','$smobile','$totcloth','$ordernum','$orderdate','$ordercloth','$clothrem')");
}
}
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<?php $orddate=date('d/m/y'); ?>
<form name="form 1" action="" method="get">
<div align="right"><input type="text" name="srch" placeholder="Search by Id or Mobile" size="25">
<input type="submit" name="search" value="Search"></div>
</form>
<form name="form2" action="" method="post">
<table>
<tr>
<td width="103">Order Date</td>
<td width="94">Customer Id</td>
<td width="53">Name</td>
<td width="71">Mobile</td>
<td width="144">Order No.</td>
<td width="144">No.of Clothes</td>
</tr>
<tr>
<td><?php echo $orddate; ?></td>
<td><?php echo @$ftch['custid']; ?></td>
<td><?php echo @$ftch['name']; ?></td>
<td><?php echo @$ftch['lname']; ?></td>
<td><?php echo @$ftch['mobile']; ?></td>
<td><input type="text" name="ordernum" required></td>
<td><input type="text" name="ordercloth" required></td>
</tr>
<tr><td colspan="8"><center><input type="submit" name="confirm" value="Confirm"></center></td></tr>
</table>
</form>
</body>
</html>
需要帮助
【问题讨论】:
-
if(isset($_POST['confirm']))。这永远不会是真的,因为您的表单方法是get。 -
好的。谢谢你的建议。但是我的问题呢
-
改了但是同样的问题,没有插入
-
可能是列名出错..echo $abc ,然后在phpmyadmin中运行查询。查询是否正确就知道了。