S
S
SteveJ422021-07-16 08:45:36
PHP
SteveJ42, 2021-07-16 08:45:36

Why is the submitted data not visible in the database?

I am new to laravel learning to send data with DB facade.
Submitted data using this code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class CreateController extends Controller
{
    public function index(Request $request)
    {
    	$title = $request->title;
    	$text = $request->text;
    	
    	\DB::insert("INSERT INTO `posts` (`title`, `text`) VALUES (?, ?)", ['$title', '$text']);
    	
    	return view('create');
    }
}

Now the problem is that instead of the sent data in phpMyAdmin, the table fields contain not the sent data, but the $title and $text variables <---that's right, it's written like this

. Tell me what to do!!!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin B., 2021-07-16
@Kostik_1993

Я новичок в laravel
------------------------
Теперь проблема в том что вместо отправленных данных в phpMyAdmin в полях таблицы стоят не отправленные данные а переменные $title и $text <---вот прям вот так и написано
By the looks of it, you're new to not only Laravel, but PHP too. As well as programming in general
['$title', '$text'] - the answer is hidden here. For what purpose did you wrap the variables in quotes?

P
pLavrenov, 2021-07-16
@pLavrenov

Read the documentation and don't be masochistic
https://laravel.com/docs/8.x/eloquent#inserts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question