我在控制器中有这个动作
public function upload() {
// getting all of the post data
$file = array('image' => Input::file('image'));
//return $file;
// setting up rules
$rules = array('image' => 'required'); //mimes:jpeg,bmp,png and for max size max:10000
// doing the validation, passing post data, rules and the messages
$validator = Validator::make($file, $rules);
if ($validator->fails()) {
// send back to the page with the input data and errors
// return Redirect::to('upload')->withInput()->withErrors($validator);
return "error validation";
}
else {
// checking file is valid.
if (Input::file('image')->isValid()) …Run Code Online (Sandbox Code Playgroud) 我的代码中目前有一个 JSON 模式
{
'type' => 'object', 'required' => true, 'additionalProperties' => false,
'properties' => {
'variables' => {
'type' => 'array', 'required' => true,
'items' => {
'type' => 'object', 'required' => true, 'additionalProperties' => false,
'properties' => {
'variable' => { 'type' => 'string', 'required' => true },
'value' => { 'required' => true }
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图在值字段上进行一些额外的验证。例如,如果是字符串,则长度不应超过 64 个字符,如果是整数,则值应在整数限制内。我应该如何定义这个模式。
这是我的Cardview代码:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TitleText(text: "Item name mmmmmmmmm $index"),
SizedBox(height: 20.0),
Body1Text(text: "Discount mmmmmmmm",color: Colors.red,),
SizedBox(height: 5.0),
SubHeadText(text: "Price ,mmmmmmmmmmmmmmmmmm",color: Colors.red,)
],
),
Run Code Online (Sandbox Code Playgroud) 我为此找到了很多似乎对我不起作用的答案。当我在变量 $message 和 $email 和 $date 周围有撇号时
'VALUES ('$message', '$email', '$date')';
Run Code Online (Sandbox Code Playgroud)
它告诉我
解析错误:语法错误,意外的“$message”(T_VARIABLE)
当我删除它们时,我得到类似无法输入数据的信息:“字段列表”中的未知列“$message”。我试过插入
$message = mysql_real_escape_string($message);
$email = mysql_real_escape_string($email);
$date = mysql_real_escape_string($date);
Run Code Online (Sandbox Code Playgroud)
用“”围绕变量,如
'VALUES ("$message", "$email", "$date")';
Run Code Online (Sandbox Code Playgroud)
它摆脱了错误消息,但现在,而不是来自 html 表单的输入,我在我的数据库中得到字面上的“$message”。
我做错了什么?我的简单目标就是将电子邮件、消息和日期放入数据库中。请帮忙!谢谢!
这是我拥有的完整代码:
<?php
if($_POST && isset($_POST['email'], $_POST['essay'])) {
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn=mysql_connect($dbhost, $dbuser);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Ink", $conn);
date_default_timezone_set("America/New_York");
$message = $_POST['essay'];
$email = $_POST['email'];
$date = date("y-m-d h:i:sa");
$sql = 'INSERT INTO inktable '.
'(writings, …Run Code Online (Sandbox Code Playgroud) 我使用glob来捕获我的图像:
$images = glob("img/lot/".$_SESSION["lotNumb"].$ds."*.jpg")
Run Code Online (Sandbox Code Playgroud)
当我回应这个时,我得到了这个:
Array
(
[0] => img/lot/01/1.jpg
[1] => img/lot/01/2.jpg
[2] => img/lot/01/3.jpg
[3] => img/lot/01/4.jpg
)
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用ltrim将其简化为文件名,但这是我在foreach循环中得到的.做这个的最好方式是什么?
这个:
foreach($images as $image)
{
$image = ltrim($image, "img/lot/".$lot);
echo $image;
}
Run Code Online (Sandbox Code Playgroud)
给我这个:
.JPG
2.JPG
3.JPG
4.JPG
我在第一次迭代时失去了"1".