I keep getting this error when trying to make an insert field for my price data. On the database it is a float type. I am not sure how to fix this and most answers online suggest that the values and fields don't match but that doesn't seem to be the case in my code.
尝试为我的价格数据创建插入字段时,我一直收到此错误。在数据库上,它是一个浮点类型。我不知道如何解决这个问题,大多数在线答案都表明值和字段不匹配,但在我的代码中似乎并非如此。
insert.php:
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
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');
?>
2 个解决方案
#1
1
You have an error in your query here,
您的查询中有错误,
'$price' '$image',
change above to,
改为上面,
'$price', '$image',
Good Luck!
祝你好运!
#2
0
$query="INSERT INTO product (Brand,Description,Price,Image,Name)
VALUES('$name','$description','$price','$image','$caption')";
#1
1
You have an error in your query here,
您的查询中有错误,
'$price' '$image',
change above to,
改为上面,
'$price', '$image',
Good Luck!
祝你好运!
#2
0
$query="INSERT INTO product (Brand,Description,Price,Image,Name)
VALUES('$name','$description','$price','$image','$caption')";