Answer the question
In order to leave comments, you need to log in
How to make changes to multiple cells of a MySql database table through ORM RedBean php?
I logged into the site with a login and password, now I need to implement a change in user information.
There is a users table in the database (id, user_name, user_surname, user_age, user_thirdname, email, password).
I use sessions in php when logging in, and when logging in, the user gets into his personal account, where he can change information about himself, for this I use findOne, but when I make changes (name and age), it gives an error:
Fatal error: Uncaught RedBeanPHP\RedException: Expected array, NULL given.
Here is the code:
<?php
require "db.php";
$data = $_POST;
// изменение данных
if ( isset($_POST['change'])) {
$findUserMail = R::findOne('users', 'email = ?', $data['email']);
if ($findUserMail) {
$findUser->user_name = $data['user_name'];
$findUser->user_surname = $data['user_surname'];
$findUser->user_thirdname = $data['user_otchestvo'];
$findUser->user_age = $data['user_age'];
R::store($findUser);
} else {
echo "<script>alert(\"В введённых данных возникла ошибка: \");</script>";
}
}
//выход из аккаунта и из сессии
if ( isset($_POST['out']) ) {
unset($_SESSION['logged_user']);
header("Location:/index.php");
}
<form action="/index2.php" method="POST">
<p>Изменить личные данные</p>
<input type="text" placeholder="имя" name="user_name" required minlength="2" >
<input type="text" placeholder="фамилия" name="user_surname" required minlength="2" >
<input type="text" placeholder="отчество" name="user_otchestvo" required minlength="2" >
<input type="text" placeholder="возраст(лет)" name="user_age" required >
<button type="submit" name="change">Изменить</button>
</form>
Answer the question
In order to leave comments, you need to log in
In general, somehow * I thought of it myself - here is the solution:
$id = $_SESSION['logged_user']->id;
$id = (int)$id;
if ( isset($_POST['change'])) {
$findUser = R::findOne('users', 'id = ?', [$id]);
$findUser->user_name = $data['user_name'];
$findUser->user_surname = $data['user_surname'];
$findUser->user_thirdname = $data['user_otchestvo'];
$findUser->user_age = $data['user_age'];
R::store($findUser);
header("Location:/index2.php");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question