我正在为一个学校项目做一个电子商务网站。我试图弄清楚当上传要插入到数据库中的图像时如何分配上传者ID,以便稍后如果其他帐户上的其他用户搜索由该特定上传者上传的图像,那么需要通过将图像更改为产品文件来制作买卖网站平台。但是为了使它更容易,我将首先尝试使其与图像一起使用。
我设法通过搜索图像的类别来创建可行的搜索功能。现在我面临的问题是我为图像分配用户ID的方式是否正确。我有一个单独的数据库用于产品和用户,我在想是否要使它工作我还应该将用户和产品表放在一个数据库中?
这是我从上传文件的教程改变的初始代码,前提是它不是空的
// if no error occured, continue ....
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('INSERT INTO product_tbl(productName, productPrice,productPic,productDescription,productCategory) VALUES(:pname, :pprice, :ppic, :pdesc, :pcat)');
$stmt->bindParam(':pname',$productname);
$stmt->bindParam(':pprice',$productprice);
$stmt->bindParam(':ppic',$productpic);
$stmt->bindParam(':pdesc',$productdesc);
$stmt->bindParam(':pcat',$productcategory);
if($stmt->execute())
{
$successMSG = "new record succesfully inserted ...";
header("refresh:5;products.php"); // redirects image view page after 5 seconds.
}
else
{
$errMSG = "error while inserting....";
}
}
我可能想到的是创建一个类似的功能,例如:
$uID = $_POST['user_ID'];
$stmt = $DB_con->prepare('INSERT INTO product_tbl(userID, productName, ...)
VALUES(:uID, :pname, .., :..)');
$stmt->bindParam(':uID',$userID);
这是一种将用户ID与上传文件相关联的正确方法吗?
抱歉,我最近需要以快节奏的方式学习php。这就是我的数据库的样子
for products files details, for user registration details
他们都在一个单独的数据库中