-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
103 lines (88 loc) · 3.88 KB
/
Copy pathdatabase.php
File metadata and controls
103 lines (88 loc) · 3.88 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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "automotive";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "<h1>Database Fix Script</h1>";
// Check if payment_proof column exists and its type
$result = $conn->query("SHOW COLUMNS FROM bookings LIKE 'payment_proof'");
if ($result->num_rows > 0) {
$column = $result->fetch_assoc();
echo "Current payment_proof column type: " . $column['Type'] . "<br>";
// If it's not VARCHAR, modify it
if (strpos(strtolower($column['Type']), 'varchar') === false && strpos(strtolower($column['Type']), 'text') === false) {
echo "Altering payment_proof column to VARCHAR(255)...<br>";
if ($conn->query("ALTER TABLE bookings MODIFY payment_proof VARCHAR(255)")) {
echo "Successfully changed payment_proof column type to VARCHAR(255)<br>";
} else {
echo "Error changing column type: " . $conn->error . "<br>";
}
} else {
echo "payment_proof column is already a text type. No changes needed.<br>";
}
} else {
echo "payment_proof column doesn't exist. Adding it...<br>";
if ($conn->query("ALTER TABLE bookings ADD payment_proof VARCHAR(255)")) {
echo "Successfully added payment_proof column<br>";
} else {
echo "Error adding column: " . $conn->error . "<br>";
}
}
// Also check the history table if it exists
$result = $conn->query("SHOW TABLES LIKE 'history'");
if ($result->num_rows > 0) {
echo "<h2>Checking history table</h2>";
$result = $conn->query("SHOW COLUMNS FROM history LIKE 'payment_proof'");
if ($result->num_rows > 0) {
$column = $result->fetch_assoc();
echo "Current payment_proof column type in history table: " . $column['Type'] . "<br>";
// If it's not VARCHAR, modify it
if (strpos(strtolower($column['Type']), 'varchar') === false && strpos(strtolower($column['Type']), 'text') === false) {
echo "Altering payment_proof column in history table to VARCHAR(255)...<br>";
if ($conn->query("ALTER TABLE history MODIFY payment_proof VARCHAR(255)")) {
echo "Successfully changed payment_proof column type to VARCHAR(255) in history table<br>";
} else {
echo "Error changing column type in history table: " . $conn->error . "<br>";
}
} else {
echo "payment_proof column in history table is already a text type. No changes needed.<br>";
}
} else {
echo "payment_proof column doesn't exist in history table. Adding it...<br>";
if ($conn->query("ALTER TABLE history ADD payment_proof VARCHAR(255)")) {
echo "Successfully added payment_proof column to history table<br>";
} else {
echo "Error adding column to history table: " . $conn->error . "<br>";
}
}
}
// Create uploads directory if it doesn't exist
$upload_dir = 'uploads/payments/';
if (!file_exists($upload_dir)) {
echo "Creating uploads directory: $upload_dir<br>";
if (mkdir($upload_dir, 0777, true)) {
echo "Successfully created directory<br>";
} else {
echo "Failed to create directory: " . error_get_last()['message'] . "<br>";
}
} else {
echo "Uploads directory already exists<br>";
}
// Check directory permissions
echo "Directory permissions: " . substr(sprintf('%o', fileperms($upload_dir)), -4) . "<br>";
if (!is_writable($upload_dir)) {
echo "Setting directory permissions to 777...<br>";
if (chmod($upload_dir, 0777)) {
echo "Successfully set permissions<br>";
} else {
echo "Failed to set permissions: " . error_get_last()['message'] . "<br>";
}
}
$conn->close();
echo "<p>Database fix completed. <a href='admin_dashboard.php'>Return to dashboard</a></p>";