I am facing A PHP Error was encountered - database

When I try to access my website member login area, I experiencing multiple errors those were not there earlier.
Please help me look into it.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: number
Filename: controllers/Site.php
Line Number: 42
Backtrace:
File:
/home/internetsunivers/2xcash.internetsuniversity.com/application/controllers/Site.php
Line: 42 Function: _error_handler
File: /home/internetsunivers/2xcash.internetsuniversity.com/index.php
Line: 315 Function: require_once A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by
(output started at
/home/internetsunivers/2xcash.internetsuniversity.com/system/core/Exceptions.php:271)
Filename: helpers/url_helper.php
Line Number: 564
Backtrace:
File:
/home/internetsunivers/2xcash.internetsuniversity.com/application/controllers/Site.php
Line: 50 Function: redirect
File: /home/internetsunivers/2xcash.internetsuniversity.com/index.php
Line: 315 Function: require_once
Following is the code in site.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends MY_Controller {
public function index()
{
$this->header(':::SONNY SERVER:::');
$data['site_name'] = $this->site_name;
$this->load->view('home');
$this->footer();
}
public function about() {
$this->header('About | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->load->view('about');
$this->footer();
}
public function faq() {
$this->header('FAQ | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->load->view('faq');
$this->footer();
}
public function support() {
$this->header('Contact Support | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->load->view('support');
$this->footer();
}
public function login() {
$this->header('Login');
$this->form_validation->set_rules('number', 'Phone Number', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run()) {
if ($this->core_model->login()) {
$query = $this->db->get_where('users', array('number' => $number));
$result = $query->row_array();
$name = $result['name'];
$bank_details = $result['bank_details'];
$session_data = array('number' => $_POST['number'], 'loggedin' => TRUE, 'name' => $name);
$this->session->set_userdata($session_data);
redirect(site_url('dash'));
}
elseif ($this->db->get_where('users', array('number' => $this->input->post('number'), 'is_blocked' => 'true'))->num_rows() > 0) {
$this->session->set_flashdata('error', 'Account has been blocked, contact suppport');
} else {
$this->session->set_flashdata('error', 'Login failed');
}
$this->load->view('login');
} else {
$this->load->view('login');
}
}
public function register() {
$this->header('Register | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->form_validation->set_rules('name', 'Fullname', 'required');
$this->form_validation->set_rules('number', 'Phone Number', 'required');
$this->form_validation->set_rules('location', 'Location', 'required');
$this->form_validation->set_rules('bundle', 'Bundle', 'required');
$this->form_validation->set_rules('bank_details', 'Bank Details', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('c_password', 'Confirm Password', 'required|matches[password]');
if($this->form_validation->run()) {
$this->core_model->register();
//register session
$session_data = array('number' => $_POST['number'], 'loggedin' => TRUE, 'name' => $_POST['name'], 'bank_details' => $_POST['bank_details']);
$this->session->set_userdata($session_data);
$this->session->set_flashdata('msg2', 'Successfully registered');
redirect(site_url('spillover'));
$this->load->view('register');
} else {
$this->load->view('register');
}
$this->footer();
}
public function logout() {
$data = array('number', 'loggedin', 'name');
$this->session->unset_userdata($data);
redirect('login');
}
}

Related

Wordpress React JS based template website not working after upgrading to PHP 8.1

After switching from PHP 7.4.30 to PHP 8.1, my WordPress website, which was built by the original developer using React JS, started acting strangely. The menus stopped working and the home page became frozen and immovable.
Enable the debug and below are some of them.
Deprecated: Optional parameter $menu declared before required parameter $location is implicitly treated as a required parameter in \app\public\wp-content\themes**\functions\classes\Settings\Menu.php on line 22
**
<?php
namespace ThemeClasses\Settings;
class Menu
{
public function __construct()
{
add_action('after_setup_theme', [$this, 'registerNavMenus']);
add_filter('getMenuTree', [$this, 'getMenuTree'], 10, 2);
}
public function registerNavMenus()
{
register_nav_menus([
'header_menu' => __('Header Menu', 'siri'),
'footer_menu' => __('Footer Menu', 'siri'),
'footer_columns' => __('Footer Columns', 'siri'),
]);
}
public function getMenuTree($menu = [], $location)
{
$flatMenu = $menu;
$flatMenu = $this->getMenuItems($menu, $location);
$treeMenu = [];
$itemsRefs = [];
foreach ($flatMenu as $menuItemObj) {
$itemId = $menuItemObj->ID;
$parentId = $menuItemObj->menu_item_parent;
$itemsRefs[$itemId] = [
'name' => $menuItemObj->title,
'url' => $menuItemObj->url,
'target' => $menuItemObj->target,
'active' => $menuItemObj->active,
'ID' => $itemId,
'parentId' => $parentId,
'children' => [],
];;
if ($parentId == 0) {
$treeMenu[] = &$itemsRefs[$itemId];
} elseif (isset($itemsRefs[$parentId])) {
$itemsRefs[$parentId]['children'][] = &$itemsRefs[$itemId];
}
}
return $treeMenu;
}
private function getMenuItems($menu, $location)
{
// Get all locations
$locations = get_nav_menu_locations();
// Get object id by location
$menuObject = wp_get_nav_menu_object($locations[$location]);
// Check menu exists
if (!is_object($menuObject)) return [];
// Get menu items by menu slug
$menu = wp_get_nav_menu_items($menuObject->slug);
// Return menu post objects
return $menu;
}
}
**Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in public\wp-content\themes**r\functions\classes\WordPressSecurity.php on line 364
// add the filter
add_filter('wp_admin_css', function($url, $file) {
errol_log($url);
// make filter magic happen here...
return $url;
}, 10, 2 );
}
public function removeWPVersion($src)
{
global $wp_version;
parse_str(parse_url($src, PHP_URL_QUERY), $query);
if (!empty($query['ver']) && $query['ver'] === $wp_version) {
$src = remove_query_arg('ver', $src);
}
return $src;
}

save the record of bulk sms sent into db laravel

i have taken the id and mobile_num from users table.i have to insert that id name in this table as user_id,mobile_num,and status(0,1) into another table(wc_sms_status).sendSMSFunction is working fine.
public function SendBulkSms()
{
$usersNumber = User::select('id','mobile_num')->whereIn('id', [5,6,7,8])->get();
foreach($usersNumber as $userNumber)
{
if (!$userNumber->mobile_num)
{
$this->sendSmsFunction($userNumber->mobile_num);
DB::table('wc_sms_status')->insert([
['user_id' => 'id'],
['mobile_num' => 'mobile_num'] // set the status=1 // how query can be changed?
]);
}
elseif($userNumber->mobile_num == exist && status == 0)
{
$this->sendSmsFunction($userNumber->mobile_num);
$this->save();
}
else{
}
}
}
Do this :
public function SendBulkSms()
{
//assuming there is a relationship between your model users and wc_sms_status called wcSmsStatus
$usersNumber = User::with('wcSmsStatus')->select('id','mobile_num')->whereIn('id', [5,6,7,8])->get();
foreach($usersNumber as $userNumber)
{
if (!$userNumber->mobile_num)
{
$this->sendSmsFunction($userNumber->mobile_num);
DB::table('wc_sms_status')->insert([
'user_id' => $userNumber->id,
'mobile_num' => $userNumber->mobile_num,
'status' => 1,
]);
} elseif ($userNumber->mobile_num && $userNumber['wcSmsStatus']->status === 0)
{
$this->sendSmsFunction($userNumber->mobile_num);
$this->save();
} else {
}
}
}
public function SendBulkSms()
{
$users = User::select('id','mobile_num')
->whereIn('id', [5,6,7,8])
->whereNotNull('mobile_num')
->get();
$bulkData = [];
foreach ($users as $user)
{
$this->sendSmsFunction($userNumber->mobile_num);
DB::table('wc_sms_status')->insert([
['user_id' => 'id'],
['mobile_num' => 'mobile_num'] // set the status=1 // how query can be changed?
]);
$bulkData[] = [
'user_id' => $user->id,
'mobile_num' => $user->mobile_num,
];
}
if (!empty($bulkData)) {
WcSmsStatus::insert($education); // change to your model name
unset($bulkData);
}
}
try to use in this way, it will insert bulk data, dont fergot to mention protected $fillable[] in model

Why is this not saving into my database? Trying to save into two tables

I'm trying to save a question that has options, those options are saved into another table than the question itself.
This is my controller
public function store(Request $request)
{
DB::beginTransaction();
$preg = new SurveyQuestion;
$preg->question = $request->question;
$preg->survey_section_id = $request->survey_section_id;
$preg->response_type_id = $request->response_type_id;
$preg->optional = $request->optional;
$preg->save();
if ($request->get('questionOptions')) {
$options = [];
$preg_id = $preg->id;
foreach ($request->get('questionOptions') as $item) {
$option = $item['option'];
if (isset($survey_question_id, $option)) {
$options[] = [
"survey_question_id" => $preg_id,
"option" => $option
];
}
}
if (count($options)) {
SurveyQuestionOption::insert($options);
}
}
DB::commit();
return back();
}
These are the tables
Schema::create('survey_questions', function (Blueprint $table) {
$table->increments('id');
$table->string('question');
$table->integer('survey_section_id')->unsigned();
$table->integer('response_type_id')->unsigned();
$table->boolean('optional');
$table->timestamps();
$table->foreign('survey_section_id')->references('id')->on('survey_sections');
$table->foreign('response_type_id')->references('id')->on('response_types');
});
Schema::create('survey_question_options', function (Blueprint $table) {
$table->increments('id');
$table->string('option');
$table->integer('survey_question_id')->unsigned();
$table->timestamps();
$table->foreign('survey_question_id')->references('id')->on('survey_questions');
});
The relationships go like this
SurveyQuestion -> hasMany -> SurveyQuestionOption
SurveyQuestionOption -> belongsTo -> SurveyQuestion
In my vue I have questionOptions as an array with objects inside and have it set up like this because I need the questions with options to have a minimum of two and I'm sending it in the submit method like follows
questionOptions: [
{
option: ''
},
{
option: ''
},
],
submit() {
this.$refs.form.validate((valid) => {
if (valid) {
this.loading = true;
this.$inertia.post(this.baseUrl, {
question: this.form.question,
survey_section_id: this.form.survey_section_id,
response_type_id: this.form.response_type_id,
optional: this.form.optional,
questionOptions: this.form.questionOptions
}).then(
() => {
this.survey_question = this.$page.survey_question;
this.$message({
type: 'success',
message: 'Creado correctamente.'
});
this.loading = false
},
(res) => {
this.$message.error(parseError(res)[0]);
this.loading = false;
})
}
} else {
return false;
}
this.reset();
});
},
The reason I'm doing it like this is because some of the questions don't have these options, only about 1/4 have them as it depends on the response type selected. But it's not saving it. Any help is appreciated.

Angular - Display Dashboard and other component.html based on user_id

Am unable to display component.html and dashboard based on user_id
I am using Angular to connect to Laravel endpoints. I have User model and other models. Every other tables have user_id in it. There are two dashboards: admin-dashboard and user-dashboard.
Laravel
public function login()
{
$credentials = request(['email', 'password']);
if (!$token = auth()->attempt($credentials)) {
return response()->json(['error' => 'Email or Password doesn\'t exisit'], 401);
}
return $this->respondWithToken($token);
}
models for user, student and assignment:
protected $fillable = [
'name', 'email', 'password', 'username',
];
protected $fillable = [
'name', 'class', 'user_id',
];
protected $fillable = [
'title', 'valid_date', 'content', 'user_id',
];
Angular: Service
private baseUrl = 'http://localhost/cloudengine-sandbox/cloudsandboxbackend/public/api';
//private baseUrl = '/api';
constructor(private http:HttpClient) { }
register(data){
return this.http.post(`${this.baseUrl}/register`, data)
}
login(data){
return this.http.post(`${this.baseUrl}/login`, data)
}
login.component.ts
onSubmit() {
this.Jarwis.login(this.form).subscribe(
data => this.handleResponse(data),
error => this.handleError(error)
);
}
handleResponse(data){
this.Token.handle(data.access_token);
this.Auth.changeAuthStatus(true);
//this.user.loggedInUser = user;
this.router.navigateByUrl('/admindashboard');
}
When I login:
If user_id is 1, it should redirect to admindashboard else userdashboard
The admin should see everything in the application, while other users should see the components/forms that its table has the user_id of that particular user
Just add a if check inside the handleResponse method,
handleResponse(data){
if(this.user.user_id == 1){
this.router.navigateByUrl('/admindashboard');
}
else
{
this.router.navigateByUrl('/userdashboard');
}
}
better way to do this should be using a Using Route Guards.

internal error undefined index

I am getting internal error
in AdminController.php line 85
at HandleExceptions->handleError('8', 'Undefined index: name', 'C:\wamp64\www\laravel\dev.oasis-portal.my\app\Http\Controllers\AdminController.php', '85', array('data' => array())) in AdminController.php line 85
when I run
public function courseDelete()
{
$data = Input::all();
$student = Course::where('name', '=', $data["name"]);
if($student->delete()) {
User::find($data["name"])->delete();
return json_encode(array('success' => true));
} else {
return json_encode(array('success' => false, 'errors' => "Unable to remove student."));
}
}
My route is: Route::get('/course/delete/', 'AdminController#courseDelete');
$data["name"] is not set, and therefore an exception is thrown. A better solution would be to get parameters by using the request() shorthand:
ie. request()->get('name'); //will return null if not set

Resources