gpt4 book ai didi

php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'name' cannot be null

转载 作者:行者123 更新时间:2023-11-29 18:10:09 28 4
gpt4 key购买 nike

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into products (name, type, img_url, updated_at, created_at) values (, , img/products/IMG-20170921-WA0003.jpg, 2017-11-24 15:31:41, 2017-11-24 15:31:41))



PHP 代码
 public function Products(Request $request){

if($request->isMethod('post'))
{
if(Input::hasFile('file')){

$myproduct = new Product();
$myproduct->name=$request->input('name');
$myproduct->type=$request->input('type');

$file = Input::file('file');
$url='img/products/'.$file->getClientOriginalName();
$file->move('img/products',$file>getClientOriginalName());
$myproduct->img_url = $url;

$myproduct->save();
return view("controlpanel.products");
}
}}

HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<table>
<tr>
<form action="{{ URL('products') }}" method="post" enctype="multipart/form-data" class="container">
<td>
<label for="name">Product Name</label>
<input type="text" name="name" class="form-control" id="name" required>
</td>
<td>
<label for="type">Product Type</label>
<select class="form-control" name="type" id="type">
<option value="type1">type 1</option>
<option value="type2">type 2</option>
</select>
</td>
<td>
<label for="file">Select Product image :</label>
<input type="file" name="file" id="file">
</td>
<td>
<input type="submit" value="Upload" name="submit" id="sub1">
<input type="hidden" value="{{ csrf_token() }}" name="_token">
</td>
</form>
</tr>
</table>
</body>
</html>

所以除了img_url之外,列名和类型都为空,我不知道为什么?请帮忙

最佳答案

我假设您正在使用 laravel。要获取输入值,您可以尝试使用此代码作为您的名称和类型字段。

$myproduct->name=$request->name;
$myproduct->type=$request->type;

关于php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'name' cannot be null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47476967/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com