简体   繁体   English

我无法使用php将信息插入到mysql数据库中

[英]I can't insert information into mysql database using php

I'm trying insert car information into my database but it's giving me in error every time. 我正在尝试将汽车信息插入我的数据库,但它每次都给我错误。

This is the code 这是代码

if(move_uploaded_file($file_tmp,"productimages/".$file_name))
         {
            $sql="INSERT INTO `products`(`ptitle`, `pprice`, `pdesc`, `modal`, `pcate`, `image`,`feat`,`uid`,`edate`) VALUES ('".$title."',".$price.",'".$desc."',".$modal.",".$cate.",'".$file_name."',0,".$_SESSION["uid"].",'".$edate."')";
            $result=mysqli_query($con,$sql);
            if($result)
            {
            echo "<script>window.location.href='add-car.php?msg=1'</script>";
            }
            else
             {
                echo "<script>window.location.href='add-car.php?error=2'</script>";
             }
         }
         else
         {
            echo "<script>window.location.href='add-car.php?error=2'</script>";
         }

This is the database: 这是数据库: 在此输入图像描述

Can you try this? 你能试试吗?

$sql="INSERT INTO products (ptitle, pprice, pdesc, modal, pcate, image,feat,uid,edate) VALUES ('$title', $price,'$desc','$modal',$cate,'$file_name',0,$_SESSION["uid"],'$edate')";

EDIT:- I have updated the code. 编辑: - 我已经更新了代码。 I could see you data has a combination of both int and varchar. 我可以看到你的数据有int和varchar的组合。 Try to not use quotes for int and keep quotes for varchar types. 尽量不要为int使用引号并为varchar类型保留引号。

Use below code and post error here so we can resolve that 使用下面的代码并在此处发布错误,以便我们解决该问题

$sql="INSERT INTO `products`(`ptitle`, `pprice`, `pdesc`, `modal`, `pcate`, `image`,`feat`,`uid`,`edate`) VALUES ('".$title."',".$price.",'".$desc."',".$modal.",".$cate.",'".$file_name."',0,".$_SESSION["uid"].",'".$edate."')";
$result=mysqli_query($con,$sql) or die(mysqli_error($con));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM