<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ProvisionServer extends Controller
{
public function insertform(){
return view('stud_create');
}
public function insert(Request $request){
$name = $request->input('stud_name');
DB::insert('insert into student (name,age) values(?,?)',[$name, $age]);
echo "Record inserted successfully.<br/>";
echo '<a href="/insert">Click Here</a> to go back.';
}
}
Route::get('insert',[StudInsertController::class'insertform']);
Route::post('create',[StudInsertController::class'insert']);
<html>
<head>
<title>添加 - 学生管理</title>
</head>
<body>
<form action = "/create" method = "post">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<table>
<tr>
<td>名字:</td>
<td><input type='text' name='stud_name' /></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type='text' name='stud_age' /></td>
</tr>
<tr>
<td colspan = '2'>
<input type = 'submit' value = "添加学生"/>
</td>
</tr>
</table>
</form>
</body>
</html
|