addtomeal.php
<?php
$hostname="localhost";
$username="root";
$password="tiger";
$dbhandle = \mysqli_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$select= \mysqli_select_db($dbhandle,"sample")
or mysqli_error($dbhandle);
$itemId= \filter_input(\INPUT_GET,'itemId');
$orderid= \filter_input(\INPUT_GET,'orderid');
$subtitle= \filter_input(\INPUT_GET,'subtitle');
$price= \filter_input(\INPUT_GET,'price');
$quantity= \filter_input(\INPUT_POST,'quantity');
$tnumber= \filter_input(\INPUT_GET,'tnumber');
if(!empty(\filter_input(\INPUT_POST,'addtomeal')))
{
$sql="insert into addtomeal(orderid,itemId,subtitle,price,quantity,tnumber)values
(NULL,'$orderid',$subtitle',$price','$quantity','$tnumber')";
/* @var $result type */
$result= \mysqli_query($dbhandle,$sql) or die(\mysqli_error($dbhandle));
}
echo "success";
mysqli_close($dbhandle);
项
<html>
<head>
<link rel="stylesheet" type="text/css" href="display.css" >
<title>Login Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
</head>
<body>
<form name="customer" id='c1' method="post" action="cartdb.php">
<script src="samcheck.js"></script>
<div id="top">
<?php session_start(); ?>
<div id="toplbl">Welcome <?php echo $_SESSION["name"]?></div>
<?php session_start(); ?>
<div id="toplbl1">This is Table Number <?php echo $_SESSION["tnumber"]?></div>
</div>
<div id="d3"><?php echo "$descript1" ; ?> </div>
<div id="s3"><?php echo "$subtitle1" ;?> </div>
<div id="r3"><?php { echo "$price1" ;} ?> </div>
<div id='t3'><?php echo "$title1"; ?> </div>
<label id="q1">Quantity</label>
<input type='text' id='q' name='q' value='1'>
<input type="hidden" name="itemId" value="<?php $itemId1 ?>">
<input type ='button' name='plus' value='+' id='p' onclick="increase()">
<input type='button' name='minus' value='-' id='m' onclick="decrease()">
<input type='button' name='cancel' value='Cancel' id='cancel' onclick="location.href='customersvsoup.php'">
<input type='submit' name='addtomeal' value='Add to my Meal' id='addtomeal'>
<?php if($itemId==='oepd1007'){
echo "<img src='getdesserticecreamimage.php?itemId=oepd1007' alt='image'> ";}
?>
</form>
</body>
</html>
我收到错误,因为列计数与第1行的值计数不匹配。我已经使用items.php中的echo语句显示所有值到addtomeal.php,这里我只得到数量。我已在items.html页面中指定了这些内容。
答案 0 :(得分:1)
这两个变量$price'
和$subtitle'
(NULL,'$orderid', $subtitle', $price','$quantity','$tnumber')
^ // there ^ // there
将其更改为:
(NULL,'$orderid','$subtitle','$price','$quantity','$tnumber')
答案 1 :(得分:1)
您的查询中似乎缺少引号:
$sql = "insert into addtomeal (orderid, itemId, subtitle, price, quantity, tnumber) values
(NULL, '$orderid', '$subtitle', '$price', '$quantity', '$tnumber')";
我不知道你的字段的类型,我为所有字段放置了引号,但如果类型是数字,则不需要使用引号。
答案 2 :(得分:0)
$ sql =“INSERT INTO addtomeal(orderid,itemId,subtitle,price,quantity,tnumber)VALUES ('$ orderid','$ itemid','$ subtitle','$ price','$ quantity','$ tnumber')“;
不要从查询中输入NULL在创建表时从表结构的默认值中输入NULL 我猜你在查询中缺少$ itemid,我在上面的查询中添加了它,并且还删除了NULL