Jump to content

All Activity

This stream auto-updates

  1. Today
  2. the session.save_path setting in the php.ini is pointing to a now non-existent/non-accessible folder. you need to see of there is already an appropriate folder within your account's directory tree /home/rgxb6tc5wk5q/... for session data files and set the session.save_path setting to point to it, and if a folder doesn't exist, create it and set the session.save_path setting to point to it. when your account was created/moved they should have had templates setup to do this automatically.
  3. I am not sure if this is a cpanel problem or coding problem. I found another post from 4 years ago with almost an identical error code and it had something to do with an ini file in the cpanel i think. I am not very good with the cpanel, so im at a loss. I talked with several people from godaddy yesterday. They said they can't help even though whatever they did caused the problem. This is for a golf leage that I wrote most of the code for several years ago. They could take me back to php 5.6. This was written around 5.2 I believe. I am not very good with php! This is the error I am getting: start error [28-Mar-2024 12:52:36 UTC] PHP Warning: session_start(): open(/var/cpanel/php/sessions/ea-php56/sess_6308705c679006fc92d1c71ffed09d18, O_RDWR) failed: No such file or directory (2) in /home/rgxb6tc5wk5q/public_html/golf/login/login.php on line 20 [28-Mar-2024 12:52:36 UTC] PHP Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/ea-php56) in /home/rgxb6tc5wk5q/public_html/golf/login/login.php on line 20 end of error. Sure would appreciate any help!! Please let me know if you need code. Charlie
  4. i recommend that you make a new file with the code necessary to load the phpmailer script and with your sendEmailNotification() function in it, setup some test data, and call the sendEmailNotification() function and get the email to work. once you get the email to work on its own, then make sure that your full code is actually calling the sendEmailNotification() function, by echoing/logging a value at the completion of the email code. you are performing a redirect right after the INSERT query. it's possible that the sms code will take enough time to make the curl request that the browser can abort the current request and halt code execution before your code gets to the email code. it's also possible that the curl code is throwing an error and your code never gets to the email code. any such redirect needs to be at the end of the post method form processing code, it should only occur if there are no user/validation errors, and it should be to the exact same URL of the current page to cause a get request for that page. here's a list of things that will simplify the code, making it easier to see what the code is trying to do - you should only catch and handle database exceptions for user recoverable errors, such as when inserting/updating duplicate user submitted data. for all other insert/update query error numbers, just rethrow the exception and let php handle it and for all other type of queries, let php catch and handle any database exception. for the INSERT query you should be catching and testing for a duplicate index error number. if an applicant can only register once, the applicant_id column should be defined as a unique index, so that only one record per applicant_id can be inserted. if an applicant can only register for a single exam_date_id, the combined applicant_id and exam_date_id columns need to be defined as a composite unique index. if you set the default fetch mode to assoc when you make the database connection, you won't have to specify it in each fetch statement. don't copy variables to other variables for nothing. just use the original variables that data is in.
  5. I have an admission application form, and I want an email and SMS notification to be sent to the applicant's email and phone upon successful registration. I have tried using the mail() function, but I am not receiving any email notifications at the recipient's email. I also tried using Gmail, but none of them are working. I used Composer to install the vendor autoload, but it is still not working. I don't know where the error is coming from. Below are the tables and the code: Table CREATE TABLE applicants ( id INT AUTO_INCREMENT PRIMARY KEY, application_id VARCHAR(20) UNIQUE, surname VARCHAR(100), othername VARCHAR(100), dob DATE, phone VARCHAR(20), email VARCHAR(100), lga VARCHAR(100), state_origin VARCHAR(100), current_school VARCHAR(100), current_class VARCHAR(50), proposed_class ENUM('Year 7 (JSS1)', 'Year 8 (JSS2)', 'Year 10 (SS1)', 'Year 11 (SS2)', 'Year 1 (PRY 1)', 'Year 2 (PRY 2)', 'Year 3 (PRY 3)', 'Year 4 (PRY 4)'), status VARCHAR(20) DEFAULT 'Pending' ); CREATE TABLE exam_dates ( id INT AUTO_INCREMENT PRIMARY KEY, exam_date DATE, type ENUM('Online', 'On-site'), is_past BOOLEAN DEFAULT FALSE ); CREATE TABLE exam_registrations ( id INT AUTO_INCREMENT PRIMARY KEY, applicant_id INT, exam_date_id INT, FOREIGN KEY (applicant_id) REFERENCES applicants(id), FOREIGN KEY (exam_date_id) REFERENCES exam_dates(id) ); ALTER TABLE applicants ADD registered_on DATETIME; PHP <?php session_start(); require_once('db_config.php'); //require_once(__DIR__ . '/../vendor/autoload.php'); require_once('vendor/autoload.php'); // Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Fetch available exam dates from the database try { $stmt = $pdo->query("SELECT * FROM exam_dates WHERE is_past = FALSE"); $exam_dates = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } // Check if the user is logged in as an applicant if (!isset($_SESSION['user_type']) || $_SESSION['user_type'] !== 'applicant') { header("Location: login.php"); exit(); } // Logout logic if (isset($_POST['logout'])) { session_destroy(); // Destroy all session data header("Location: login.php"); // Redirect to the login page exit(); } // Set the applicant_id from the applicants table try { $username = $_SESSION['username']; $stmt = $pdo->prepare("SELECT * FROM applicants WHERE application_id = ?"); $stmt->execute([$username]); $applicant = $stmt->fetch(PDO::FETCH_ASSOC); $_SESSION['applicant_id'] = $applicant['id']; $applicant_email = $applicant['email']; // Store the applicant's email address } catch(PDOException $e) { echo "Error: " . $e->getMessage(); exit(); } // Check if the applicant has already registered for an exam date try { $stmt = $pdo->prepare("SELECT * FROM exam_registrations WHERE applicant_id = ?"); $stmt->execute([$applicant['id']]); $registered_exam_dates = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } // Handle exam registration if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['exam_date'])) { // Check if the applicant has already registered for an exam date if (!empty($registered_exam_dates)) { //echo "You have already registered for an exam date."; exit(); } $applicant_id = $_SESSION['applicant_id']; $exam_date_id = $_POST['exam_date']; // Insert exam registration details into exam_registrations table try { $stmt = $pdo->prepare("INSERT INTO exam_registrations (applicant_id, exam_date_id) VALUES (?, ?)"); $stmt->execute([$applicant_id, $exam_date_id]); // Redirect to exam confirmation page or show success message header("Location: exam_confirmation.php"); // Send SMS to applicant $message = "Thank you for your application. Your username is: " . $applicant['application_id'] . " and Password is your surname."; $api_url = 'my api url'; $token = 'my token'; $sender = 'Olu'; $recipient = $applicant['phone']; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $api_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array( 'token' => $token, 'sender' => $sender, 'to' => $recipient, 'message' => $message, ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo 'SMS sent successfully.'; } // Send email notification to applicant using PHPMailer sendEmailNotification($applicant_email, $applicant['application_id'], $applicant['surname']); exit(); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } } // Function to send email notification using PHPMailer function sendEmailNotification($recipientEmail, $applicationId, $surname) { // Instantiate PHPMailer $mail = new PHPMailer(true); try { // SMTP configuration (Gmail) $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'olu@gmail.com'; $mail->Password = 'mypassword'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; // Email content $mail->setFrom('olu@gmail.com', 'My Schol'); $mail->addAddress($recipientEmail); $mail->Subject = 'Application Registration Confirmation'; $mail->isHTML(true); $mail->Body = "Dear $surname,<br><br>Thank you for your application at my Schol. Your username is: $applicationId and Password is your surname.<br><br>Best regards,<br>My Schol"; // Send email $mail->send(); echo 'Email sent successfully!'; } catch (Exception $e) { echo "Error: {$mail->ErrorInfo}"; } } ?> <!DOCTYPE html> <html> <head> <title>Applicant Dashboard</title> <script> // JavaScript function to display a popup function displayPopup() { alert("You have already registered for an exam date."); } </script> </head> <body> <h2>Welcome, <?php echo $applicant['surname']; ?></h2> <!-- Display applicant information --> <p>Applicant's Name: <?php echo $applicant['surname'] . ' ' . $applicant['othername']; ?></p> <p>Application ID: <?php echo $applicant['application_id']; ?></p> <p>Date of Birth: <?php echo $applicant['dob']; ?></p> <p>Phone: <?php echo $applicant['phone']; ?></p> <p>Email: <?php echo $applicant['email']; ?></p> <p>Local Government Area: <?php echo $applicant['lga']; ?></p> <p>State of Origin: <?php echo $applicant['state_origin']; ?></p> <p>Current School: <?php echo $applicant['current_school']; ?></p> <p>Current Class: <?php echo $applicant['current_class']; ?></p> <p>Proposed Class: <?php echo $applicant['proposed_class']; ?></p> <!-- Selected exam date --> <p>Selected Exam Date: <?php if (!empty($registered_exam_dates)) { $selected_exam_date_id = $registered_exam_dates[0]['exam_date_id']; foreach ($exam_dates as $date) { if ($date['id'] == $selected_exam_date_id) { echo date('F j, Y', strtotime($date['exam_date'])) . " (" . $date['type'] . ")"; break; } } } else { echo 'Not selected'; } ?> </p> <hr> <!-- Exam date selection --> <h3>Exam Date Selection</h3> <form id="exam_form" method="post"> <label for="exam_date">Select Exam Date:</label><br> <select id="exam_date" name="exam_date"> <?php foreach ($exam_dates as $date) : ?> <option value="<?php echo $date['id']; ?>"><?php echo $date['exam_date'] . " (" . $date['type'] . ")"; ?></option> <?php endforeach; ?> </select><br><br> <input type="button" value="Register for Exam" onclick="checkExamRegistration()"> <!--<input type="submit" value="Register for Exam">--> </form> <!-- Application status --> <h3>Application Status</h3> <p>Status: <?php echo $applicant['status']; ?></p> <!-- Logout form --> <form method="post"> <input type="submit" name="logout" value="Logout"> </form> <script> // Function to check if the applicant has already registered function checkExamRegistration() { <?php if (!empty($registered_exam_dates)): ?> displayPopup(); <?php else: ?> document.getElementById("exam_form").submit(); <?php endif; ?> } </script> </body> </html>
  6. Last week
  7. Visual Studio can be a powerful IDE for PHP development with the help of plugins and extensions. Below are the steps to set up PHP_CodeSniffer for coding standards and Xdebug for debugging with breakpoints in Visual Studio, along with some alternative tools: PHP_CodeSniffer Setup: PHP_CodeSniffer helps maintain coding standards in your project. You can integrate it into Visual Studio using the following steps: First, install PHP_CodeSniffer globally using Composer. Open your command line interface and run: composer global require "squizlabs/php_codesniffer=*" Next, you'll need to add PHP_CodeSniffer as an external tool in Visual Studio. Go to Tools > External Tools. Click on Add and fill in the following fields: Title: PHP_CodeSniffer Command: Enter the path to the phpcs.bat file. This can typically be found in C:\Users\YourUsername\AppData\Roaming\Composer\vendor\bin. Arguments: --standard=PSR2 $(ItemPath) Initial directory: $(ItemDir) Check the option for "Use Output window". Click OK to save. Now, you can use PHP_CodeSniffer by right-clicking on a PHP file in Solution Explorer, and then selecting PHP_CodeSniffer from the Tools menu. It will check your code against PSR2 coding standards. Best Regard Danish hafeez | QA Assistant ICTInnovations Xdebug Setup: Xdebug is a PHP extension that allows for debugging PHP scripts. Here's how you can set it up in Visual Studio: First, download and install Xdebug on your server. You can follow the instructions on the Xdebug website. Once installed, configure Xdebug in your php.ini file. Make sure to set xdebug.remote_enable=1 and xdebug.remote_autostart=1. In Visual Studio, you'll need to install the "PHP Debug" extension. Go to Extensions > Manage Extensions. Search for "PHP Debug" and install it. Configure PHP Debug extension: Go to Tools > Options. Navigate to PHP Tools > Debugging. Set the "Xdebug Port" to the port configured in your php.ini file (default is 9000). Click OK to save the settings. Now, you can set breakpoints in your PHP code and start debugging by pressing F5 or clicking on the Start Debugging button. Alternate Tools: If you find the setup process for PHP_CodeSniffer and Xdebug too complicated, or if you're looking for alternatives, you can consider the following: PHP Mess Detector (PHPMD): Similar to PHP_CodeSniffer, PHPMD focuses on detecting potential problems in your code. PHPCSFixer: This tool automatically fixes many coding standard violations reported by PHP_CodeSniffer. DBGp Proxy: An alternative to Xdebug for debugging PHP applications. Visual Studio Code: If you're open to using a different IDE, Visual Studio Code has excellent support for PHP development with extensions available for PHP_CodeSniffer and Xdebug integration. Choose the tools that best fit your requirements and preferences.
  8. foreach ($data as $cards) { $cards = json_decode($data['cards'], true); $count = sizeof($cards); $out = ''; if ($count == 4) { $size = "col-xl-3 col-md-6"; } else if ($count == 3) { $size = "col-xl-4 col-md-4"; } else if ($count == 2) { $size = "col-xl-6 col-md-6"; } else if ($count == 1) { $size = "col-12"; } foreach ($cards as $cardName => $cardDetails) { $icon_code = $icons[$cardDetails['Icon']]; $out .= "<div class='$size mb-3'> <div class='card editHeroCard' data-card='$cardName'> <div class='card-body'> <div class='text-center card-title'> <i class='$icon_code fa-2xl'></i> </div> <div class='card-text text-center my-3 fw-bold'>$cardDetails[Name]</div> <div class='card-text text-center'>$cardDetails[Paragraph]</div> </div> </div> <div class='handle text-center'>GRAB</div> </div>"; }
  9. I have a function that contains the following: foreach ($data as $cards => $row) { print_r($data); the data that is printed is as follows: Array ( [cards] => {"Card 1": {"This": "Something 1", "Paragraph": "This is the first card", "Icon": 562, "Order": 5}, "Card 2": {"This": "Something 2", "Paragraph": "This is the second card", "Icon": "559", "Order": 2}, "Card 3": {"This": "Somethihg 3", "Paragraph": "This is the third card", "Icon": "560", "Order": 3}, "Card 4": {"This": "Something 4", "Paragraph": "This is the fourth card", "Icon": "561", "Order": 4}} ) I want to "get" "Card 1", "Card 2"... How in a loop can i access this part of the array. I have tried print_r $data, $cards and $row and none of them give me what i need. When i try and use [0] i just get the first letter.
  10. I have been looking at documentation and it seems that something like this is the route that i need to take - but i am getting no results in php my admin when running this query. SELECT portal_content_json from portal_content where JSON_SEARCH( portal_content_json, 'all', 2, Null, ' $[*]."Hero Cards[*]"."Order"') IS NOT NULL;
  11. your current approach is flawed because you're updating the IDs in a loop without considering the existing IDs in the database. Also, the update query inside the loop doesn't seem to be properly updating the IDs. <?php echo "<table class='tabela_dados' border='1'> <tr> <td>ID</td> <td>Nome Empresa</td> <td>Responsável</td> <td>Telefone 1</td> <td>Telefone 2</td> <td>E-mail 1</td> <td>E-mail 2</td> <td>Endereço</td> <td>CEP</td> <td>Bairro</td> <td>AÇÃO 1</td> <td>AÇÃO 2</td> </tr> "; $sql = "SELECT * FROM usuarios_dados WHERE Usuario='$usuario'"; $result = $conn->query($sql); if ($result->num_rows > 0) { $Novo_ID = 1; while ($row = $result->fetch_assoc()) { // Update the ID in the database $old_ID = $row['ID']; $sql_update = "UPDATE usuarios_dados SET ID='$Novo_ID' WHERE ID='$old_ID'"; $conn->query($sql_update); // Output the row with the updated ID echo "<tr> <td>$Novo_ID</td> <td>{$row['Nome_Empresa']}</td> <td>{$row['Responsavel']}</td> <td>{$row['Telefone_1']}</td> <td>{$row['Telefone_2']}</td> <td>{$row['Email_1']}</td> <td>{$row['Email_2']}</td> <td>{$row['Endereço']}</td> <td>{$row['CEP']}</td> <td>{$row['Bairro']}</td> <td> <form method='post' action='Editar_Dados.php'> <input type='hidden' name='usuario' value='$usuario'> <input type='hidden' name='senha' value='$senha'> <input type='hidden' name='ID' value='$Novo_ID'> <input type='submit' style='padding: 10px;' value='EDITAR'> </form> </td> <td> <form method='post' action='Deletar_Dados.php'> <input type='hidden' name='usuario' value='$usuario'> <input type='hidden' name='senha' value='$senha'> <input type='hidden' name='ID' value='$Novo_ID'> <input type='submit' style='padding: 10px;' value='DELETAR'> </form> </td> </tr>"; $Novo_ID++; } } else { echo "0 results"; } echo "</table>"; $conn->close(); ?> This code will assign sequential IDs starting from 1 to each row in the database table while displaying the data in the HTML table. Make sure to replace $usuario and $senha with appropriate variables if they are defined elsewhere in your code. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  12. welcome to phpfreaks i hope you will get proper help from this forum and you will also help other if you will understand questions. Best Regard Danish hafeez | QA Assistant ICTInnovations
  13. You need to output a row number, not the actual id. One way is to increment a $rowno variable each time you output a row of your query results and output that. Alternatively, there are a couple of ways you can do it with a single query. Test data TABLE: reindeer +----+---------+ | id | name | +----+---------+ | 1 | Comet | | 3 | Cupid | | 4 | Dasher | | 6 | Vixen | | 8 | Prancer | | 10 | Dancer | | 15 | Donner | | 16 | Blitzen | +----+---------+ Using an SQL variable SELECT @rowno := @rowno+1 as rowno , name , id FROM reindeer JOIN (SELECT @rowno := 0) as init ORDER BY name; Using the ROW_NUMBER() window function (MariaDB v11 or MySql v8) SELECT ROW_NUMBER() OVER (order by name) as rowno , name , id FROM reindeer ORDER BY name; Both the above output +-------+---------+------+ | rowno | name | id | +-------+---------+------+ | 1 | Blitzen | 16 | | 2 | Comet | 1 | | 3 | Cupid | 3 | | 4 | Dancer | 10 | | 5 | Dasher | 4 | | 6 | Donner | 15 | | 7 | Prancer | 8 | | 8 | Vixen | 6 | +-------+---------+------+
  14. your initial post is meaningless. I-m trying to do the following !! (I THINK YOU MEANT TO write I'm instead of I-m. At least I hope you do.) What is the following? You don't say what it is you are trying to do. Listing data in the table !! Listing data is a normal procedure for programmers to accomplish. What is the problem? You don't say. I would like....if the list has 4 rows..whetever the ID list is..make the ID list 1 2 3 4 !! Example.....if have a list with ID 1 3 3...make stay 1 2 3 !! If you have an "ID" of some sort in your database then it should not be altered and it should be UNIQUE. Yet - you are saying that when displayed you want the "ID" to be modified to show your records with a new consecutive list of ids that are not what your database should be showing. WHY WOULD ANYONE DO THAT? Maybe you need to explain in English what it is you are trying to do.
  15. Earlier
  16. This is great - i can confirm that it did what i needed so thanks for that. Now i just need to workout how to select by order Number in order to update the values when the data is edited.
  17. Record IDs ... should be unique. should never be changed should never be reallocated Breaking those rules destroys the integrity of your database. And as for you update query, what is the point of setting the id to X where the id = X. That is like you changing your username on this forum to "Legendary_003"
  18. you are not enabling php error checking or you would be seeing a lot of error messages. Turn it on! For example: $row[ID] is an invalid line. Any reference to an array value must either be a php variable or a text value wrapped in quotes to identify it as text or else a number. After that - I don't have a clue what you are trying to write. $row['ID'] This is how it needs to be in your case.
  19. Hello... I-m trying to do the following !! Listing data in the table !! I would like....if the list has 4 rows..whetever the ID list is..make the ID list 1 2 3 4 !! Example.....if have a list with ID 1 3 3...make stay 1 2 3 !! Follow the try next: echo "<table class='tabela_dados' border='1'> <tr> <td>ID</td> <td>Nome Empresa</td> <td>Responsável</td> <td>Telefone 1</td> <td>Telefone 2</td> <td>E-mail 1</td> <td>E-mail 2</td> <td>Endereço</td> <td>CEP</td> <td>Bairro</td> <td>AÇÃO 1</td> <td>AÇÃO 2</td> </tr> "; $sql = "SELECT ID FROM usuarios_dados WHERE Usuario='$usuario'"; $result = $conn->query($sql); $num_rows = $result->num_rows; $Novo_ID = 1; for ($i = 0; $i < $num_rows; $i++) { $registro = $result -> fetch_row(); $sql2 = "UPDATE usuarios_dados SET ID='$Novo_ID' WHERE ID='$Novo_ID'"; $result2 = $conn->query($sql2); $Novo_ID++; } $sql = "SELECT * FROM usuarios_dados"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<tr> <td>$row[ID]</td> <td>$row[Nome_Empresa]</td> <td>$row[Responsavel]</td> <td>$row[Telefone_1]</td> <td>$row[Telefone_2]</td> <td>$row[Email_1]</td> <td>$row[Email_2]</td> <td>$row[Endereço]</td> <td>$row[CEP]</td> <td>$row[Bairro]</td> <td> <form method='post' action='Editar_Dados.php'> <input type='hidden' name='usuario' value='$usuario'> <input type='hidden' name='senha' value='$senha'> <input type='hidden' name='ID' value='$row[ID]'> <input type='submit' style='padding: 10px;' value='EDITAR'> </form> </td> <td> <form method='post' action='Deletar_Dados.php'> <input type='hidden' name='usuario' value='$usuario'> <input type='hidden' name='senha' value='$senha'> <input type='hidden' name='ID' value='$row[ID]'> <input type='submit' style='padding: 10px;' value='DELETAR'> </form> </td> </tr> "; } } else { echo "0 results"; } $conn->close();
  20. Just going back a bit to your question, and some short history: Under the covers, the XMLHttpRequest() was a non-standard addition to the official DOM api, first added in by microsoft. While it was an important idea, as it was not standard, and not every browser maker was eager to add the feature in, so there's still code floating around that was aimed at specific browsers (microsoft in particular, as they were the inventor of it). With that said, it's at the core of all "ajax". The acronym "AJAX" is short for "Asynchronous JavaScript and XML" which in reality rarely involves XML anymore. Most people use json as the data transport format and not xml. $.ajax() is the grandparent of javascript libraries: jquery. Just a quick aside, but Jquery was the first to popularize taking advantage of the fact that javascript allows you to name a variable '$'. It doesn't own the use of $, being that it's just an alias for the jquery object, but regardless, there's so much code around that used demonstrated $.ajax() people still associate it with jquery, and to be fair, it was a nice improvement over hand coding all DOM manipulation code yourself. The ajax() method is just a small part of jquery, but it's still popular with many developers for its simplicity and ease of implementation. It was also created prior to a number of improvements to javascript itself, in particular ES6. And it's still the best known wrapper around XMLHttpRequest, although there have been any number of other libraries around that people used to do the same thing. In recent years, people have moved away from jquery (which is a large library) in favor of other more lightweight and problem specific libraries. In the ajax coding world, one popular competitor to using jquery for ajax is Axios. As for the fetch api, it is an entirely different animal, being that it was designed as an alternative to the use of XMLHttpRequest and was part of an initiative to provide more robust support for http request/response architecture. In other words, it was purpose built as an alternative to using XMLHttpRequest. One of the main reasons you want to write code that uses fetch, is that fetch was built on top of ES6 and inherently uses Promises. Just in case you aren't clear on this, prior to promises, people used callbacks. The more complicated the code the more likely you were to have a mess of interwoven callbacks, leading to the phrase "callback hell". So promises were introduced into the language as an alternative to callbacks. The fetch api returns a Promise object, and you will often see code that uses it that way, with a chain of code like this: fetch(url, options) .then((response) => response.json()) .then((data) => { console.log(data); }); You might also notice, that using fetch, not unlike using the native XMLHttpRequest function is built into the browser. You don't need a library to do it. Looking back on it, what Axios attempted to do, was bridge the gap between the introduction of Promises and an api that allowed you to write promise based code, only under the covers it was still using XMLHttpRequest. Unlike Axios, you don't need any library... just put your fetch code in there, and it already hides lots of complexity and works for you. Last but not least, given the intrinsic use of Promises, anyone can also take advantage of the syntactic sugaring of Async Await when writing your fetch api code.
  21. I would first check the VS PHP extension to see what support it has; probably not PHP_CodeSniffer, but quite possibly Xdebug. If not then there's a good chance you're out of luck - because nobody uses Visual Studio for PHP. And, frankly, you should take that as a hint, and go for a PHP IDE (like PhpStorm) or switch to VS Code (at least for this). Don't get me wrong, I like Visual Studio. I think it's a great platform. But software development is about using the right tool for the job.
  22. Hi all, My name is Lokesh Joshi and I am new here.
  23. Using VS code we are able to find tools. We used PHP_CodeSniffer and xdebugg in VS Code. We are not able to find such tools in Visual Studio.
  24. XMLHttpRequest is a bit outdated these days with the rise of the fetch API. That having been said, the fetch API can be a bit rough to wrap one's brain around if you're new to it. Either way, one option is to add an additional parameter to the AJAX calls (for instance, 'ajaxRequest') that isn't set in the normal call expecting a full page refresh. Check for that extra parameter in the processing code and you know how to return the data - either a JSON string of just the data or the entire page. I'm a little brain-fried, so I hope that makes sense...
  25. Your command will set the "Content Block" value to a string which happens to contain JSON data. If you want that string value to be interpreted into a JSON value then try CAST-ing it.
  26. Hey @mac_gyver , I want to thank you tremendously for your responses. After scrolling further in the tutorial that I was using I spotted a section that states EXACTLY what you mentioned above with an added caveat that there is an exception if and it then provides the necessary JavaScript. I'm not sure why there's a difference, but at this point I'm just happy to have working components that suit my needs. Nonetheless, curiosity did have me wondering, would the solution that you provided initially have worked if I had used the "more traditional" AJAX format? And yes, I understand the need for validating and sanitizing form data (but thanks for the reminder) and was more concerned that the alternate method of JavaScripting might (in itself) open a vulnerability.
  27. Hi All, I have a function: function createContentBlock($pdo, $contentBlockType, $textBlockTitle, $textBlockContent) { $portalId = $_GET['portalId']; $json = array( "Name" => $textBlockTitle, "Content" => $textBlockContent ); $sql = "UPDATE portal_content set portal_content_json = JSON_SET( portal_content_json,'$.\"Portal Content\".\"Pages\".\"Home\".\"Content Block\"', :json) WHERE portal_attachment_id = :portalId"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':portalId' => $portalId, ':json' => json_encode($json, JSON_UNESCAPED_SLASHES) ]); return "Content Block Created"; } When the data is going into the json, it looks like this: "Content Block": "{\"Name\":\"asa\",\"Content\":\"<p>asa</p>\"}" }, You will see that it is also getting an additional closing bracket. I dont know why it is going in like this as i have another function that is putting data in in the same way without this issue.
  28. I solved it! Many thanks anyway
  1. Load more activity
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.