Jump to content

Danishhafeez

Members
  • Posts

    18
  • Joined

  • Last visited

  • Days Won

    2

Danishhafeez last won the day on April 19

Danishhafeez had the most liked content!

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Danishhafeez's Achievements

Member

Member (2/5)

3

Reputation

1

Community Answers

  1. To dynamically create multiple instances of your emoji selector and text area pair, you can use a loop to generate unique IDs for each pair and then initialize the event listeners accordingly. <!DOCTYPE html> <html> <head> <title>Dynamic Emoji Selector</title> </head> <body> <!-- Add a container where the emoji selector and text area pairs will be added --> <div id="emojiContainer"></div> <!-- Your original emoji selector and text area template --> <select id="emojiSelectTemplate"> <option value="">Select a kaomoji</option> </select> <textarea name="comment_text_template" class="comment_text" rows="2" cols="40" placeholder="Type comment reply here." required></textarea> <script> document.addEventListener('DOMContentLoaded', function() { const emojis = [ '(・ω・)', '(´・ω・`)', '(。♥‿♥。)', 'ヾ(⌐■_■)ノ♪', '(╯°□°)╯︵ ┻━┻' ]; // Get a reference to the emoji container const emojiContainer = document.getElementById('emojiContainer'); // Loop to create multiple instances const numInstances = 30; // Change this to the number of instances you need for (let i = 0; i < numInstances; i++) { // Clone the template elements const emojiSelect = document.getElementById('emojiSelectTemplate').cloneNode(true); const inputText = document.getElementsByClassName('comment_text')[0].cloneNode(true); // Set unique IDs for each instance emojiSelect.id = 'emojiSelect' + i; inputText.id = 'comment_text' + i; // Append cloned elements to the container emojiContainer.appendChild(emojiSelect); emojiContainer.appendChild(inputText); // Populate the select dropdown with emojis emojis.forEach(emoji => { const option = document.createElement('option'); option.value = emoji; option.text = emoji; emojiSelect.appendChild(option); }); // Event listener for emoji selection emojiSelect.addEventListener('change', function() { const selectedEmoji = this.value; if (selectedEmoji) { inputText.value += selectedEmoji; this.selectedIndex = 0; // Reset dropdown to default option after selection } }); } }); </script> </body> </html> In this modified version: I've added a <div> with the id emojiContainer where the dynamic instances of emoji selectors and text areas will be added. The original emoji selector and text area are now considered as templates (with id="emojiSelectTemplate" and class="comment_text" respectively). Inside the loop, I clone the template elements, set unique IDs for each instance, and then append them to the container. Best Regard Danish hafeez | QA Assistant ICTInnovations
  2. To achieve this without dynamically building a query with OR conditions, you can use a JOIN with a LIKE condition. SELECT DISTINCT d.* FROM data d JOIN groupareas ga ON d.areaId = ga.areaId JOIN areas a ON ga.areaId = a.areaId JOIN ( SELECT groupId, GROUP_CONCAT(areaPath) AS areaPaths FROM groupareas ga JOIN areas a ON ga.areaId = a.areaId GROUP BY groupId ) AS grouped_areas ON ga.groupId = grouped_areas.groupId WHERE CONCAT(d.areapath, '\\') LIKE CONCAT(grouped_areas.areaPaths, '\\%') AND ga.groupId = ?; The inner subquery (grouped_areas) fetches all the area paths associated with each group and concatenates them into a single string using GROUP_CONCAT. Each group's area paths are grouped by the groupId. The main query then joins the data table with groupareas, areas, and grouped_areas subquery. It uses CONCAT to compare each areapath from the data table with the concatenated area paths of the group. The LIKE condition checks if the areapath of each data record starts with any of the concatenated area paths for the group. This effectively matches all records whose areapath is a child of any of the defined area paths for the group. Finally, the DISTINCT keyword ensures that each record is only returned once, preventing duplicates. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  3. To address layout consistency issues in HTML and CSS, ensure proper clearing of floats and utilize techniques like clearfix to prevent unexpected shifts. Additionally, employ responsive design principles and semantic HTML elements to maintain stable layouts across different screen sizes and devices. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  4. Using filter_input_array with FILTER_SANITIZE_FULL_SPECIAL_CHARS for both $_GET and $_POST can provide an additional layer of security by sanitizing input data. However, keep in mind that it may cause unintended behavior if applied indiscriminately to all input. It's generally considered safe, especially when combined with htmlspecialchars, but ensure it doesn't interfere with any specific requirements or data types in your application. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  5. You can achieve this by splitting the user input into separate keywords and then searching for each keyword individually in your database query. public function get_materials_pick($id) { // Split the user input into separate keywords $keywords = explode(" ", $id); // Construct the WHERE clause dynamically to search for each keyword $whereClause = ""; foreach ($keywords as $keyword) { $whereClause .= "(".PREFIX."tprices.ProductDesc LIKE '%$keyword%') OR "; } // Remove the last 'OR' from the WHERE clause $whereClause = rtrim($whereClause, "OR "); // Construct and execute the SQL query $sql = "SELECT ".PREFIX."tprices.IdPrice, ".PREFIX."tprices.Supplier, ".PREFIX."tprices.ProductCode, ".PREFIX."tprices.ProductDesc, ".PREFIX."tprices.Price FROM ".PREFIX."tprices WHERE $whereClause ORDER BY ".PREFIX."tprices.Price, ".PREFIX."tprices.Supplier ASC"; return $this->db->select($sql); } i hope With this modification, you can input keywords in any order, and the function will search for each of them individually in the ProductDesc column of your materials table. This should provide the flexibility you need for searching. Best regard Danish Hafeez | QA Assistant ICTInnovations
  6. To troubleshoot the email sending issue, first, verify that your SMTP configuration for Gmail is accurate, including the username, password, host, port, and encryption method (TLS). Ensure that you've enabled access for less secure apps in your Gmail settings. Additionally, set PHPMailer's SMTPDebug property to 2 to enable detailed error reporting. Double-check the recipient email address for correctness. Temporarily comment out the SMS sending code to isolate the problem. Finally, test your email sending code in a development environment to identify any potential issues with your production setup. $mail->SMTPDebug = 2; // Enable detailed error reporting // Verify SMTP configuration settings for 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; Best Regard Danish hafeez | QA Assistant ICTInnovations
  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. 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
  9. 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
  10. Ensure that the variables lblTag and errorLbl are correctly assigned and passed to the errorMessage function. Check if the elements with the IDs referenced by lblTag and errorLbl exist in the HTML. <div class="row"> <label for="a" id="lbName">Name:</label> <input type="text" name="name" id="name"> </div> <script> function checkName() { var name = document.getElementById("name").value; if (name === "") { var lblTag = "lbName"; var errorLbl = "Name"; errorMessage(lblTag, errorLbl); } } function errorMessage(lblTag, errorLbl) { console.log(errorLbl); // Check if errorLbl is correctly passed var element = document.getElementById(lblTag); if (element) { element.style.color = "red"; } else { console.error(`Element with ID "${lblTag}" not found.`); } var errorMessageElement = document.getElementById('error-lbl-message'); if (errorMessageElement) { errorMessageElement.innerHTML = errorLbl + " is empty"; } else { console.error('Error message element not found.'); } } </script> Make sure to call the checkName function whenever you need to validate the name field. This code includes checks to ensure that the elements referenced by lblTag and errorLbl exist before attempting to modify them. This can help prevent TypeErrors when trying to access properties of null or undefined. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  11. If you want to select a specific card based on its order number in the JSON structure, you can achieve that by iterating over the cards until you find the one with the desired order number. function getHeroCardByOrderNumber($pdo, $orderNumber) { $sql = "SELECT json_extract(portal_content_json, '$.\"Portal Content\".\"Pages\".\"Home\".\"Hero\".\"Hero Cards\"') as cards FROM portal_content where portal_attachment_id = :portalId"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':portalId' => $_GET['portalId'] ]); $data = $stmt->fetch(); if (!$data) { return null; // or handle the case where no data is found } $cards = json_decode($data['cards'], true); // Find the card with the given order number foreach ($cards as $card) { if ($card['Order'] == $orderNumber) { return $card; } } return null; // or handle the case where the card with the given order number is not found } You can then call this function to get the card with the specified order number: $orderNumber = 4; // Example order number $card = getHeroCardByOrderNumber($pdo, $orderNumber); if ($card) { // Display or use the card data echo "Card Name: " . $card['Name']; echo "Card Paragraph: " . $card['Paragraph']; } else { echo "Card not found."; } This modified function getHeroCardByOrderNumber will return the card data if found, or null if not found. Best regard Danish Hafeez | QA Assistant ICTInnovations
  12. It seems like your code is vulnerable to SQL injection, which could be causing issues, especially when running on the web server. It's always essential to sanitize user inputs to prevent such vulnerabilities. <?php if (isset($_GET['COMPANY_ID'])) { include('dataconn/connection.php'); // Prepare an update statement $sql = "UPDATE `MASTER_COMPANY` SET `COMPANY_STATUS`=? WHERE `COMPANY_ID`=?"; // Attempt to prepare the SQL statement if ($stmt = mysqli_prepare($con, $sql)) { // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "si", $PCompanySts, $id); // Set parameters $id = $_GET['COMPANY_ID']; $PCompanySts = "N"; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)) { session_start(); $_SESSION["delete"] = "Company Deleted Successfully!"; header("Location: /Companyindex.php"); exit(); } else { echo "Something went wrong"; } // Close statement mysqli_stmt_close($stmt); } else { echo "Error: Unable to prepare SQL statement."; } // Close connection mysqli_close($con); } else { echo "Company does not exist"; } ?> In this code: We're using prepared statements to safely execute the SQL query. User inputs are sanitized through parameter binding, reducing the risk of SQL injection. I've added exit() after the redirect header to ensure that no further code is executed after the redirection. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  13. It seems like you're trying to dynamically retrieve column names from the first loop and then use them to fetch corresponding data from the database in the second loop. However, you're facing issues with the data retrieval part. Let's correct the code: fputcsv($csvfile, $export_column_name_array, $delimiter); $stmt2 = $conn->prepare($sql_built_statement); //$stmt2->bind_param("ii", $company_id, $company_id); WILL ADD THIS LATER ONCE WORKING $stmt2->execute(); $result2 = $stmt2->get_result(); if($result2 != NULL){ // Retrieve data while($row2=$result2->fetch_assoc()){ // Initialize an empty data array for each row $data_array = array(); // Add data for each column foreach ($export_column_name_array as $value) { // Push data for each column into the data array $data_array[] = $row2[$value]; } // Write the data array to the CSV file fputcsv($csvfile, $data_array, $delimiter); } } fclose($csvfile); In this corrected code: We loop through each row of the fetched data and initialize an empty $data_array for each row. Within the row loop, we iterate through each column name from $export_column_name_array. For each column name, we fetch the corresponding data from the $row2 associative array and add it to the $data_array. After populating the $data_array with data for all columns, we write it to the CSV file using fputcsv(). The process repeats for each row fetched from the database until all rows have been processed. i hope This should correctly populate your CSV file with the data fetched from the database, using the dynamic column names obtained from $export_column_name_array. Best Regard Danish hafeez | QA Assistant ICTInnovations
  14. When a user types using the keyboard return key in a textarea, it typically creates new lines (\n) in the submitted content. So if the user types: H E L P It will be submitted as: H\nE\nL\nP When you process this content in PHP and send it via email, if you use the content as is without any modifications, the new lines will be preserved in the email. However, how the email client renders these new lines can vary. To ensure the exact format of the text entered into the form is preserved in the email, you should set the content type of the email to plain text and include appropriate headers. Here's a simple example using PHP's mail function: <?php $to = 'recipient@example.com'; $subject = 'User Request'; $message = $_POST['message']; // Assuming the textarea content is posted as 'message' $headers = 'From: your_email@example.com' . "\r\n" . 'Reply-To: your_email@example.com' . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> In this example, $_POST['message'] contains the content of the textarea. By setting the content type to text/plain, you ensure that the email will be sent as plain text without any HTML formatting, which helps preserve the exact format of the text entered by the user. Best regard Danish Hafeez | QA Assistant ICTInnovations
  15. Your script is indeed attempting to divide the SKUs between the two API keys, but there are a few issues that need to be addressed: Duplicate API URLs: You are using the same URL for both cURL handles ($url and $url2), which means you're sending the same requests with both API keys. You should generate separate URLs for each key. Incorrect API Key Assignment: The logic to assign API keys based on the chunk index isn't correct. You're assigning the same API key to both chunks if the chunk index is odd. Instead, you should alternate between the two keys for each chunk. Here's the modified script to address these issues: <?php $sku_numbers = array( '12345', '33333', '98745', '44444', '11111', '05054' ); $key1 = 'first_SECRET_key'; $key2 = 'second_SECRET_key'; $keycount = 0; foreach (array_chunk($sku_numbers, 3) as $chunk) { $api_KEY = ($keycount % 2 == 0) ? $key1 : $key2; // Alternating between keys for each chunk $sku_LISTINGS = '&sku[]=' . implode('&sku[]=', $chunk); $url = 'https://api.data_companneee.com/script.php?apiKey=' . $api_KEY . $sku_LISTINGS; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $mh = curl_multi_init(); curl_multi_add_handle($mh, $ch); $active = null; do { $status = curl_multi_exec($mh, $active); curl_multi_select($mh); } while ($status === CURLM_CALL_MULTI_PERFORM || $active); $response = curl_multi_getcontent($ch); curl_multi_remove_handle($mh, $ch); curl_multi_close($mh); // Process the response for this chunk immediately // Assuming response processing code here $keycount++; // Increment key count for the next chunk } ?> This script will now properly alternate between the two API keys for each chunk and process responses immediately after receiving them. Additionally, it sends separate requests for each API key. Make sure to add your response processing code where indicated.i hope it will solve your 50 percent issue. Best Regard Danish Hafeez | QA Assistant ICTInnovations
×
×
  • 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.