Danishhafeez
Members-
Posts
41 -
Joined
-
Last visited
-
Days Won
2
Everything posted by Danishhafeez
-
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
-
Rule set and debugger for PHP in Visual Studio
Danishhafeez replied to TeamPHP's topic in PHP Installation and Configuration
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. -
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
-
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
-
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
-
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
-
PHP Code working in local machine - But not working in webserver
Danishhafeez replied to fmax's topic in PHP Coding Help
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 -
Issue with passing Array Data from Loop1 to Loop2
Danishhafeez replied to experience40's topic in PHP Coding Help
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 -
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
-
is my curl_multi_exec "ALTERNATOR" script realllllly working?
Danishhafeez replied to ChenXiu's topic in PHP Coding Help
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 -
The issue you're encountering is due to the fact that the PHPMailer classes are not being autoloaded properly within your function func() in the testfunctions.php file. This is happening because the use statements are not sufficient to autoload the classes within the function scope. To resolve this issue, you can use require_once to include the necessary PHPMailer files within the function scope of func(). <?php function func() { ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Include PHPMailer autoloader or include necessary PHP files require_once 'PHPMailer/src/PHPMailer.php'; require_once 'PHPMailer/src/SMTP.php'; require_once 'PHPMailer/src/Exception.php'; // Create a new PHPMailer instance $mail = new PHPMailer(true); // Enable exceptions try { // SMTP configuration $mail->isSMTP(); $mail->Host = 'mail.qss.mgo.mybluehost.me'; // Your SMTP server host $mail->SMTPAuth = true; $mail->Username = 'xxxxx'; // Your SMTP username $mail->Password = 'xxxxx'; // Your SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption $mail->Port = 587; // TCP port to connect to // Sender and recipient addresses $mail->setFrom('xxxxx', 'Your Name'); // Sender's email address and name $mail->addAddress('xxxxx', 'Recipient Name'); // Recipient's email address and name // Email content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Test Email'; $mail->Body = 'This is a test email sent using PHPMailer'; // Send the email if ($mail->send()) { echo 'Email sent successfully!'; } else { echo 'Error: Email not sent.'; } } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } } ?> i hope With this change, PHPMailer classes should be properly included within the func() function scope, and you should be able to call func() from your test.php script without encountering the "Class not found" error. Best regard Danish Hafeez | QA Assistant ICTInnovations
-
Filter rows where A's are the same and B's are the same: You'll use the WHERE clause to filter rows based on these conditions. Filter rows where C=120: Again, use the WHERE clause to add this condition. Calculate the time difference between D values: You'll use date/time functions to calculate the time difference between D values in seconds. For example, in MySQL, you can use the TIMESTAMPDIFF() function. Check if the time difference is less than 3 seconds: Add another condition in the WHERE clause to filter rows where the time difference is less than 3 seconds. Here's how you can write the SQL query: SELECT * FROM tableName t1 JOIN tableName t2 ON t1.abcd = t2.abcd AND t1.1.2.3.4 = t2.1.2.3.4 WHERE t1.C = '120' AND t2.C = '120' AND t1.2024-02-27 09:59:03 = '2024-02-27 09:59:03' AND t2.2024-02-27 09:59:03 = '2024-02-27 09:59:03' AND TIMESTAMPDIFF(SECOND, t1.2024-02-27 09:59:03, t2.2024-02-27 09:59:03) < 3; In this query: tableName t1 and tableName t2 are aliases for the same table to represent two instances of the same table. JOIN tableName t2 ON t1.abcd = t2.abcd AND t1.1.2.3.4 = t2.1.2.3.4 ensures that we're joining rows where A's are the same and B's are the same. t1.C = '120' AND t2.C = '120' ensures that both instances have C = 120. TIMESTAMPDIFF(SECOND, t1.2024-02-27 09:59:03, t2.2024-02-27 09:59:03) < 3 calculates the time difference between the D values and checks if it's less than 3 seconds. You can adjust this query according to your specific SQL dialect, as some databases might have slightly different syntax for date/time functions and aliases. Additionally, make sure to replace the placeholder column names like abcd, 1.2.3.4, etc., with the actual column names from your table. Best Regard Danish Hafeez | QA Assistant ICTInnovations
-
you can achieve a similar outcome by interpreting the CSV data and creating an image based on it using PHP libraries like: GD Library: Built-in for image manipulation (drawing text, shapes, etc.). Imagick: Extends GD with wider image format support and advanced features. Here's a general approach: Read the CSV: Use fgetcsv or str_getcsv to parse the data into an array. Analyze the data: Understand the meaning of each column and how it contributes to the desired image. Create the image: Initialize an image canvas using imagecreate, setting dimensions appropriately. Iterate through the CSV data, using library functions to: Draw text, shapes, or other visual elements based on the data, potentially applying formatting as needed. Output the image: Use imagejpeg to save the created image as a JPG file. Remember to: Install required libraries (sudo apt install php-{gd|imagick} on Ubuntu/Debian). Handle potential CSV data variations for flexibility. Design the visualization logic to match your specific requirements.
-
Converting a CSV file directly to a JPG image is not a common task, as CSV files typically contain tabular data, while JPG files are images. However, if you have specific requirements for visualizing the data from the CSV file as an image, you may need to create a custom solution. Read the CSV file: Use PHP's built-in functions like fgetcsv() to read the CSV file and extract the data. Process the data: Depending on how you want to visualize the data, you'll need to process it accordingly. For example, if you want to create a chart or graph, you might need to calculate values or organize the data in a certain way. Create the image: Use libraries like GD or Imagick in PHP to create and manipulate images. You'll need to determine how to represent the data visually in the image. Save the image: Once you've created the image, save it as a JPG file using the appropriate functions. example related to this task: i hope you will understand it.