在尝试为我的价格数据设置插入字段时,我一直收到此错误消息。在数据库上,它是一个浮点类型。我不确定如何解决这个问题,大多数在线答案都表明价值和字段不匹配,但在我的代码中似乎并非如此。
insert.php:
<?php
$title="Insert a new item";
$style="css/nav.css";
$style2="css/form.css";
include('includes/header.php');
include('includes/nav.php');
require_once('connect.php');
$name = $_POST['Brand'];
$description = $_POST['Description'];
$price = $_POST['Price'];
$caption = $_POST['caption'];
$image = 'images/' . $_FILES["image"]["name"];
$query="INSERT INTO product (Brand, Description, Price, Image, Name)
VALUES('$name', '$description', '$price' '$image', '$caption')";
if (mysqli_query($connection, $query)){
echo "<p>New record added succesfully </p>";
move_uploaded_file($_FILES["image"]["tmp_name"],
"images/" . $_FILES["image"]["name"]); }
else echo "SQL Query Error: " .mysqli_error($connection);
mysqli_close($connection);
?>
insert_form.php
<?php
$title="Insert a new item";
$style="css/nav.css";
$style2="css/form.css";
include('includes/header.php');
include('includes/nav.php');
?>
<form method="post" action="insert.php" enctype="multipart/form-data">
<fieldset>
<legend>Insert a New Record</legend>
<div class="row">
<label for="Brand" class="fixedwidth">Brand:</label>
<input type="text" name="Brand" />
</div>
<div class="row">
<label for="Description" class="textbox" >Description: </label>
<textarea cols="50" rows="5" name="Description"></textarea>
</div>
<div class="row">
<label for="Price" class="fixedwidth">Price:</label>
<input type="text" name="Price" />
</div>
<div class="row">
<label for="Image" class="fixedwidth">Image</label>
<input type="file" name="image" />
</div>
<div class="row">
<label for="Name" class="fixedwidth">Image Caption</label>
<input type="text" name="caption" />
</div>
<div class="row">
<input type="submit" name="submit" value="Add" />
<input type="reset" value="Clear" />
</div>
</fieldset>
</form>
<?php
include('includes/footer.php');
?>
答案 0 :(得分:1)
您的查询中有错误,
'$price' '$image',
更改为,
'$price', '$image',
祝你好运!
答案 1 :(得分:0)
$query="INSERT INTO product (Brand,Description,Price,Image,Name)
VALUES('$name','$description','$price','$image','$caption')";