Php 如何在laravel中插入简单表单值?
resources/view/index.blade.phpPhp 如何在laravel中插入简单表单值?,php,laravel,Php,Laravel,resources/view/index.blade.php <html> <head> <title>Laravel</title> </head> <body> <form method="post" action = "/create"> <input type="text" name="fname" id="fnam
<html>
<head>
<title>Laravel</title>
</head>
<body>
<form method="post" action = "/create">
<input type="text" name="fname" id="fname" placeholder="firstname" /><br/><br/>
<input type="text" name="phone" id="phone" placeholder="phone" /><br/><br/>
<input type="submit" name="submit" id="submit" />
</form>
</body>
</html>
我是新来的。现在,我想将表单值存储到数据库表中,但是现在,它没有发生,我不知道这段代码有什么问题。所以,请帮我解决这个问题
谢谢默认情况下,
POST
在Laravel中的路由受保护。您必须在表单中添加令牌,以确保服务器接受post请求
<form method="post" action = "/create">
@csrf <!-- This blade directive generates <input type="hidden" name="_token" value="xyz..." /> -->
<input type="text" name="fname" id="fname" placeholder="firstname" /><br/><br/>
<input type="text" name="phone" id="phone" placeholder="phone" /><br/><br/>
<input type="submit" name="submit" id="submit" />
</form>
@csrf
您丢失的CSRF令牌添加此
{{ csrf_field() }}
在表单标记中添加_标记,如下所示
<html>
<head>
<title>Laravel</title>
</head>
<body>
<form method="post" action = "/create">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="fname" id="fname" placeholder="firstname" /><br/><br/>
<input type="text" name="phone" id="phone" placeholder="phone" /><br/><br/>
<input type="submit" name="submit" id="submit" />
</form>
</body>
拉维尔
添加{{csrf_field()}}操作将是action=“{url('/create')}}}”什么是错误?您可以添加错误吗?当我单击提交按钮时,它不会显示任何内容@Vipul。我正在尝试使用
http://localhost/blog/
url,其中博客包含laravel文件。如果您是laravel的新手,您需要参考官方文档,该文档将指导如何处理CRUD操作。因为那些代码比你的更简单。他们有一个标准,一个设计模式,一个命名约定。当我点击submit,但它在localhost/blog/create
上重定向我时,它抛出了一个错误,即Symfony\Component\Debug\Exception\FatalThrowableError(e_PARSE)PARSE错误:语法错误,意外的“$phone”(T_变量)
你忘了
在$fname=$request->input('fname')
之后,现在,它抛出方法notallowedHttpException没有消息
@Jerodevplease告诉我{{csrf\u field}
@Rudra for csrf令牌有什么用你可以访问这个
{{ csrf_field() }}
<html>
<head>
<title>Laravel</title>
</head>
<body>
<form method="post" action = "/create">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="fname" id="fname" placeholder="firstname" /><br/><br/>
<input type="text" name="phone" id="phone" placeholder="phone" /><br/><br/>
<input type="submit" name="submit" id="submit" />
</form>
</body>