-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.php
More file actions
158 lines (133 loc) · 6.04 KB
/
debug.php
File metadata and controls
158 lines (133 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Debug script to test database connection and table structure
* Place this file in the same directory as your other PHP files
* Access it through your browser to verify your database setup
*/
// Enable error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Database connection settings (same as in exit-interview.php)
$db_host = 'localhost';
$db_name = 'vdart_hr';
$db_user = 'root';
$db_pass = '';
echo "<h1>Database Connection Test</h1>";
// Test database connection
try {
$conn = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "<p style='color:green;'>✓ Successfully connected to the database!</p>";
// Check if tables exist
$tables = array('exit_interviews', 'exit_interview_reasons');
foreach ($tables as $table) {
$stmt = $conn->prepare("SHOW TABLES LIKE :table");
$stmt->bindParam(':table', $table);
$stmt->execute();
if ($stmt->rowCount() > 0) {
echo "<p style='color:green;'>✓ Table '{$table}' exists!</p>";
// Show table structure
$stmt = $conn->prepare("DESCRIBE {$table}");
$stmt->execute();
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<details><summary>Table Structure for '{$table}'</summary>";
echo "<table border='1' cellpadding='5' cellspacing='0'>";
echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
foreach ($columns as $column) {
echo "<tr>";
echo "<td>{$column['Field']}</td>";
echo "<td>{$column['Type']}</td>";
echo "<td>{$column['Null']}</td>";
echo "<td>{$column['Key']}</td>";
echo "<td>{$column['Default']}</td>";
echo "<td>{$column['Extra']}</td>";
echo "</tr>";
}
echo "</table></details>";
} else {
echo "<p style='color:red;'>✗ Table '{$table}' does not exist!</p>";
}
}
// Try sample insertion and deletion to test permissions
echo "<h2>Testing Database Permissions</h2>";
try {
// Begin transaction so we can roll back
$conn->beginTransaction();
// Test insert into main table
$testSql = "INSERT INTO exit_interviews (
employee_name, employee_id, designation, team,
cal_dal, bu_head, doj, dor, resign_decision,
explored_options, explored_options_desc,
specific_event, specific_event_desc,
recommend_company, recommend_company_desc,
open_to_reapply, open_to_reapply_desc,
encourage_to_stay, factors_new_role,
areas_to_improve, members_to_thank,
rating_pay, rating_training, rating_supervisor,
rating_relationship, rating_benefits, rating_promotion,
rating_performance, rating_discipline,
hrbp_note, submission_date
) VALUES (
'Test User', 'TEST123', 'Test Position', 'Test Team',
'Test Leader', 'Test Head', '01/01/2023', '02/02/2023', 'Test Decision',
'Yes', 'Test Description',
'No', '',
'Yes', '',
'Yes', '',
'Test Stay', 'Test Factors',
'Test Improve', 'Test Thanks',
'Good', 'Good', 'Good',
'Good', 'Good', 'Good',
'Good', 'Good',
'Test Note', NOW()
)";
$conn->exec($testSql);
$lastId = $conn->lastInsertId();
echo "<p style='color:green;'>✓ Successfully inserted test record into exit_interviews table (ID: {$lastId})</p>";
// Test insert into reasons table
$reasonSql = "INSERT INTO exit_interview_reasons (interview_id, reason) VALUES (:id, 'Test Reason')";
$stmt = $conn->prepare($reasonSql);
$stmt->bindParam(':id', $lastId);
$stmt->execute();
echo "<p style='color:green;'>✓ Successfully inserted test record into exit_interview_reasons table</p>";
// Rollback transaction to avoid leaving test data in the database
$conn->rollBack();
echo "<p style='color:green;'>✓ Successfully rolled back test data</p>";
} catch(PDOException $e) {
$conn->rollBack();
echo "<p style='color:red;'>✗ Error testing database permissions: " . $e->getMessage() . "</p>";
}
// Test form action URL
echo "<h2>Form Configuration Test</h2>";
$formAction = "exit-interview.php";
if (file_exists($formAction)) {
echo "<p style='color:green;'>✓ Form action file '{$formAction}' exists</p>";
} else {
echo "<p style='color:red;'>✗ Form action file '{$formAction}' does not exist!</p>";
}
$jsFile = "exit-interview.js";
if (file_exists($jsFile)) {
echo "<p style='color:green;'>✓ JavaScript file '{$jsFile}' exists</p>";
} else {
echo "<p style='color:red;'>✗ JavaScript file '{$jsFile}' does not exist!</p>";
}
$cssFile = "exit-interview.css";
if (file_exists($cssFile)) {
echo "<p style='color:green;'>✓ CSS file '{$cssFile}' exists</p>";
} else {
echo "<p style='color:red;'>✗ CSS file '{$cssFile}' does not exist!</p>";
}
} catch(PDOException $e) {
echo "<p style='color:red;'>✗ Connection failed: " . $e->getMessage() . "</p>";
// Suggest possible solutions
echo "<h2>Troubleshooting Steps:</h2>";
echo "<ol>";
echo "<li>Make sure MySQL server is running</li>";
echo "<li>Verify the database name 'vdart_hr' exists (create it if it doesn't exist)</li>";
echo "<li>Check that the username and password are correct</li>";
echo "<li>Ensure the user has permissions to access the database</li>";
echo "<li>Run the SQL script to create the required tables</li>";
echo "</ol>";
}
?>