-
Posts
252 -
Joined
-
Last visited
Community Answers
-
Moorcam's post in Only variables should be passed by reference was marked as the answer
Ok,
After more research the issue was with these two lines:
$pickupLocations, // Now properly initialized $dropLocations, // Now properly initialized These two variables are connected to a json_encode function. And, since json_encode returns a value rather than a variable, it cannot be passed by reference.
So, the fix was to predefine the json_encode and pass them then into the bind as follows:
// Prepare JSON encoded variables $pickupLocation = json_encode($charterData['pickup_location']); $dropLocation = json_encode($charterData['drop_location']); // Bind parameters $stmt->bind_param("ssssssssssssssi", $charterData['chtr_name'], $charterData['chtr_description'], $charterData['start_date'], $charterData['end_date'], $charterData['depot_start'], $charterData['depot_finish'], $charterData['driver'], $charterData['fleet_number'], $charterData['updated_by'], $charterData['customer_name'], $pickupLocation, $dropLocation, $charterData['pickup_time'], $charterData['return_time'], $charterId ); Hope this may help others in the future.
-
Moorcam's post in Opening SweetAlert in PHP echo was marked as the answer
Fixed.
The issue was with the Javascript:
// Unban User function unbanUser(userId) { Swal.fire({ title: 'Are you sure?', text: "You are about to unban this user.", icon: 'warning', showCancelButton: true, confirmButtonText: 'Yes, unban it!', cancelButtonText: 'No, cancel!', }).then((result) => { if (result.isConfirmed) { fetch("includes/unban-user.php", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: `userId=${encodeURIComponent(userId)}` }) .then(response => handleResponse(response)) .catch(error => { console.error("Error:", error); Swal.fire({ title: 'Error!', text: 'There was an issue unbanning the user.', icon: 'error', confirmButtonText: 'Okay' }); }); } }); } function handleResponse(response) { if (response.ok) { response.text().then(text => { Swal.fire({ title: 'Success!', text: text, icon: 'success', confirmButtonText: 'Okay' }).then(() => { location.reload(); // Reload the page to see the changes }); }); } else { console.error("Error: " + response.statusText); Swal.fire({ title: 'Error!', text: 'There was an issue unbanning the user.', icon: 'error', confirmButtonText: 'Okay' }); } } I was missing this part:
function handleResponse(response) { if (response.ok) { response.text().then(text => { Swal.fire({ title: 'Success!', text: text, icon: 'success', confirmButtonText: 'Okay' }).then(() => { location.reload(); // Reload the page to see the changes }); }); } else { console.error("Error: " + response.statusText); Swal.fire({ title: 'Error!', text: 'There was an issue unbanning the user.', icon: 'error', confirmButtonText: 'Okay' }); } } Thanks for your help regardless. Always appreciated.
-
Moorcam's post in Fetching array of domains from external file was marked as the answer
Ok, it now works.
I changed the domains.php file to the following:
<?php // domains.php // Array of domains $domains = [ "example.com", "example.org", "example.net", "example.edu" ]; // Set the content type to application/json header('Content-Type: application/json'); // Encode the array to JSON and output it echo json_encode($domains); ?> Changed the domains to be encased in double quotes rather than single quotes and also set the type to application/json
Although it will not work in localhost because of local certificate errors, it does work in a live server environment.
Thank you both for your help. It's appreciated.
So, for anyone wanting this, here is the rest of the code:
<?php // This script checks if the current domain is in the allowed domains list. // Function to fetch domains from the external PHP file function fetchDomains($url) { $ch = curl_init(); // Set cURL options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute cURL request $response = curl_exec($ch); // Error handling for cURL if (curl_errno($ch)) { throw new Exception('cURL Error: ' . curl_error($ch)); } curl_close($ch); // Decode the JSON response $domains = json_decode($response, true); // Error handling for JSON decoding if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('JSON Decode Error: ' . json_last_error_msg()); } return $domains; } // Main execution try { $url = 'https://www.site.com/domains.php'; // Replace with the actual URL of the external PHP file $domains = fetchDomains($url); // Get the current domain $currentDomain = $_SERVER['HTTP_HOST']; // Check if the current domain is in the fetched array if (!in_array($currentDomain, $domains)) { echo "Your domain, ($currentDomain) is not on the list."; } } catch (Exception $e) { // Handle exceptions echo "An error occurred: " . $e->getMessage(); } ?>
-
Moorcam's post in LEFT JOIN not displaying all ID's was marked as the answer
Ok, fixed.
I changed the charter ID from 'id' to 'chtr_id' in the database. Everything is now working.
-
Moorcam's post in 500 Internal error when mod_rewrite enabled was marked as the answer
Never mind,
Solved.
mod_headers was disabled, causing a conflict in .htaccess.
-
Moorcam's post in Unable to Import Excel or CSV was marked as the answer
Hi again all,
Posting this for anyone who has experienced similar.
It appears Codeigniter 3 has a bug that does not check for file extensions. Thus, not allowing certain files to be uploaded.
The workaround is to create a piece of code that will do the checking for us and allow for it to be uploaded.
Here is that little piece of code:
$ext = strtolower(pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION)); if ($ext != "csv") { // Not a CSV file - send error $this->session->set_flashdata('error', 'Incorrect file extension uploaded. Only .CSV allowed!'); redirect("admin/csv"); } Works a charm, thanks to my good friend Craig.
-
Moorcam's post in Printing Div loses style in preview was marked as the answer
If anyone else wants this, here's what solved it for me...
document.getElementById("printButton1").addEventListener("click", function() { var printContents = document.getElementById('invoice').innerHTML; var originalContents = document.body.innerHTML; var printButton = document.getElementById("printButton1"); var closeButton = document.getElementById("closeButton1"); document.body.innerHTML = printContents; document.getElementById('printButton1').style.visibility = 'hidden'; window.print(); document.body.innerHTML = originalContents; window.location.reload(true); });
-
Moorcam's post in Showing Data Assigned to User was marked as the answer
Fixed
Change the following:
<td><?php echo $job->start_date;?></td> <td><?php echo $job->name;?></td> To...
<td><?php echo $row['p_start_date']; ?></td> <td><?php echo $row['p_name']; ?></td>
-
Moorcam's post in Database Not Updating - CodeIgniter was marked as the answer
Fixed.
Was not getting id from database.
So, changed
function update($id) { $this->db->where('id',$id); $this->db->update('tbl_team_member',$data); } to this
function update($data) { $this->db->where('id',$this->session->userdata('id')); $this->db->update('tbl_team_member',$data); } Just in case anyone else runs into same issue.
-
Moorcam's post in Undefined Method was marked as the answer
Ignore my impatient and lazy outburst of the "Please rescue me!". I went and put my grown up pants on and figured it out.
I was missing some of the Model_FFleet file. Jeesh!
-
Moorcam's post in Loop icon for PHP Search was marked as the answer
<input type="text" class="searchTerm" placeholder="What are you looking for?"> <button type="submit" class="searchButton"> <i class="fa fa-search"></i> </button> You need Font Awesome. If you have it, try the above.
https://fontawesome.com/icons?d=gallery&p=2
-
Moorcam's post in Updating MySQLi from Dropdown not working was marked as the answer
<select class="form-control" name="maintreq[<?php echo $issue_id; ?>][issue_priority]"> <?php echo '<option value="'.$issue_priority.'">'.$issue_priority.'</option>'; ?> <option value="High">High</option> <option value="Medium">Medium</option> <option value="Low">Low</option> </select> </td> <td class="text-center"> <select class="form-control" name="maintreq[<?php echo $issue_id; ?>][issue_status]"> <?php echo '<option value="'.$issue_status.'">'.$issue_status.'</option>'; ?> <option Value="Open">Open</option> <option Value="Pending">Pending</option> <option value="Repaired">Repaired</option> </select> That better?
It works now though. Nothing getting deleted or anything and everything gets updated the way I want.
-
Moorcam's post in Undefined index on $_SESSION was marked as the answer
Got it.
The issues was me being stupid.
I will not go there