-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Thanks for the clarification! I removed the line from my post.
-
As I'm sure you know, the learning process can be frustrating, especially when things don't seem to click...and/or when rushed to find a solution. Feel free to come back if you decide to tackle the problem again. To go along with Barand's suggestion, one option to show PHP errors is adding the following to the top of your script while debugging: <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ?> Side note: the link below shows the PHP versions that are actively being supported. https://www.php.net/supported-versions
-
Are you getting the error when running Billing_Import.php? If so, have you looked into minimizing the queries executed within the foreach loop? I'm guessing that the script is running 31,000 select queries, for example. What about building a single query in advance...then running it after processing the 31,000 rows?
-
That's likely part of the PhpSpreadsheet solution being used. This is probably the GitHub repo: https://github.com/PHPOffice/PhpSpreadsheet/tree/master/src/PhpSpreadsheet/Cell
-
Were you able to fix the error? As requinix described, you are currently using the procedural style for calling mysqli_query(), which requires 2 arguments. You already included the query. Now you need to provide the database connection object, as the first argument. Based on the following line, your connection object is stored in $conn: $conn = mysqli_connect($servername, $username, $password); So, your call to mysqli_query() would look like the following: $query_result = mysqli_query($conn, $query);
-
Can connect to DB but can't extract data
cyberRobot replied to rtsanderson's topic in PHP Coding Help
It looks like you're using MySQLi to connect, but using the old MySQL functions for the rest. Note that the old functions were removed in PHP 7.0. See the warning here: https://www.php.net/manual/en/function.mysql-query.php -
PHP 8.1 How can I stop warning messages from displaying?
cyberRobot replied to SLSCoder's topic in PHP Coding Help
What about hiding all errors and warnings (on the production side) generated by PHP? Then write code to handle error cases the user is more likely to experience (e.g., incorrect login, invalid record ID, etc.) and output custom / user-friendly error messages. Side note: If you haven't already, you may want to consider the potential security impacts of outputting the raw PHP errors. https://www.php.net/manual/en/security.errors.php -
In case you are still looking for an answer, the issue might be caused by .background-image being defined twice. The definition in your styles.css is being ignored in this case, since you override all the rules in the <style> tag for the page. For example, the following rule from styles.css background-image: url(blueSunset.jpg); Is overridden by the following rule in the <style> tag: background-image: url('/blueSunset.jpg'); Note that the first rule says your image is in the same folder as the stylesheet...where the second rule says the image is in the root directory (note the slash). If the image isn't in the root directory, it won't show up.
-
You could use CSS (e.g., Flexbox or Grid) to accomplish that. Flexbox example: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox Grid example: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout CSS can also be used for zebra striping.
-
How can I get the page height which can change after element hiding?
cyberRobot replied to eaglehopes's topic in HTML Help
One option would be to write a function that gathers the necessary height information. Then run the function to initialize your height variable(s). If something is hidden after the initialization, run the function again to update the variable(s). You could also check to see if there's an event listener built into JavaScript for detecting changes to the page height. If something like that is available, you could have that run the necessary code to update the height information. For example, the "resize" event listener might be useful when gather height information when the user changes their browser's window size. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event Additional listeners may be available for other events that impact page height. -
Perhaps you already got this by Barand's response. If not, maybe this will help: Curly: ‘ ’ Straight: ' ' I should also mention that your original code posted at the top of this thread also had a curly double quote. Curly: “ ” Straight: " " Hopefully, you can see the curve in the curly quotes. Of course, the look of curly quotes are different based on the font used, as you may have noticed with Barand's response.
-
One thing I don't think was mentioned is to be wary of smart / curly quotes. I'm guessing those are remnants from copying code from a blog post. Be aware that PHP requires straight quotes. The following, for example, ‘expected-timeline-for-buying’ should be 'expected-timeline-for-buying'
-
Returning a value if blank in mysql with php
cyberRobot replied to PNewCode's topic in PHP Coding Help
Too be honest, I'm still not sure what $pageimg contains. My guess is that it contains the result object that's returned when you run the query. It's difficult to tell without seeing the code. $row["pageimg"] on the other hand will contain just the image name for whichever row (i.e., $row) is being processed by the loop extracting data from the result object. -
Returning a value if blank in mysql with php
cyberRobot replied to PNewCode's topic in PHP Coding Help
I believe that's what kicken was trying to help us figure out. Seeing how $pageimg is defined should let us know what the variable contains. You could add the following debug lines to see what the different variables contain: echo '<pre>' . print_r($pageimg, true) . '</pre>'; echo '<pre>' . print_r($row["pageimg"], true) . '</pre>'; -
Returning a value if blank in mysql with php
cyberRobot replied to PNewCode's topic in PHP Coding Help
To me it seems like the code should be this. Note that I changed $pageimg to $row["pageimg"]. //IF IMAGE NAME IS PROVIDED, SHOW CUSTOM IMAGE if (!empty($row["pageimg"])) { $imagePageURL = '/img/'.$row["pageimg"]; //ELSE...SHOW FALLBACK IMAGE } else{ $imagePageURL = 'nouserback.jpg'; } -
Returning a value if blank in mysql with php
cyberRobot replied to PNewCode's topic in PHP Coding Help
If I'm understanding correctly, $pageimg indicates if the row is empty or not. Then $row["pageimg"] contains the file name, if available. Is that correct? If so, shouldn't you be testing whether or not $row["pageimg"] contains a value? If it does, use the image name...else, use nouserback.jpg. -
Returning a value if blank in mysql with php
cyberRobot replied to PNewCode's topic in PHP Coding Help
Note that you're using two different variables for the page image ($row["pageimg"] and $pageimg). Is that intentional? -
FYI - The extra PHP tags are unnecessary. Developers will sometimes break out of PHP to output some HTML, for example. Then go back into PHP to do more work. The close PHP tag "?>" and the open PHP tag "<?php" in the code below can be removed without issue. while($row = $result->fetch_assoc()) { ; ?> <?php error_reporting(E_ALL); More information about PHP tags can be found here: https://www.php.net/manual/en/language.basic-syntax.phptags.php Also, I just noticed there's a rogue semi-colon after the while loop line above. The semi-colon can be removed.
-
The error is caused by the code remnant at the end of the string here: <br><br>",60); Try this instead: <br><br>"; On an unrelated note, the following code is unnecessary: $resultt = mysqli_query($conn, "select COUNT(id) AS count FROM `copypaste`"); if(!$result) { die('Error: ' . mysqli_error($link)); } else { $num_rows = mysqli_fetch_assoc($resultt); // echo it echo ""; } You don't seem to be using that $num_rows variable. Plus, you can get the same information from the earlier query...which you use here: if ($result->num_rows > 0) {
-
Deleting the fields wouldn't change the aesthetic. The fields won't show because the are gone. However, it's starting to sound like I'm missing something. Perhaps you have some JavaScript that unhides the fields so they can be edited. If there's a purpose like that, feel free to ignore the suggestion.
-
The following values / fields are all "hidden", so they're not really important to the form. I would delete the fields. If you need the "cost_price" information after the form is submitted, you could query the database using the ID passed via "check_list". That way you can be sure the value hasn't been tampered with by the user. It's very easy to go into the code in the browser and modify "hidden" fields. So, someone could modify the price to be 0, for example. <input type='text' name='prod_id[<?= $prod_id] ?>' value='<?= $prod_id ?>' hidden> <input type='text' name='cost_price[<?= $prod_id] ?>' value='<?= $cost_price ?>' hidden> <input type='text' name='prod_name[<?= $prod_id] ?>' value='<?= $prod_name ?>' hidden> <input type='text' name='size_type[<?= $prod_id] ?>' value='<?= $size_type ?>' hidden> <input type='text' name='sold_price[<?= $prod_id] ?>' value='<?= $sold_price ?>' hidden> <input type='text' name='prod_qty[<?= $prod_id] ?>' value='<?= $prod_qty ?>' hidden> <input type='text' name='total_price[<?= $prod_id] ?>' value='<?= $total_price ?>' hidden> Now, if the form will eventually be modified so that all fields (e.g., cost_price, prod_qty, etc.) can be updated by the user, then it makes sense to have all those fields. Of course, those fields wouldn't be "hidden" in that case.
-
Sorry about that, the IDs need to be enclosed in PHP tags. Here's an updated example: <td><input type='checkbox' name='check_list[<?= $prod_id ?>]' value='<?= $prod_id ?>' ></td> <input type='text' name='prod_id[<?= $prod_id ?>]' value='<?= $prod_id ?>' hidden> <input type='text' name='cost_price[<?= $prod_id ?>]' value='<?= $cost_price ?>' hidden> ...
-
With that said, is there a reason for sending the hidden fields? I didn't spend too much analyzing the code, but it seems like you're just passing values that are already in the database. If any of that information is needed after the form is submitted, you could use the ID from the checkbox to pull the necessary values from the database. That way you don't need to worry about someone potentially tampering with the "hidden" fields.
-
As Barand mentioned, only the checked checkboxes will be passed via $_POST. If you have 20 checkboxes and only 2 are checked, the array for $_POST['check_list'] will only have 2 elements...where the other arrays (e.g., $_POST['prod_id']) will have 20. So, the use of $k in the code above won't work since there's no guarantee the array indexes will line up between $_POST['check_list'] and the other arrays. To get a better picture of what's going on after the form is submitted, you could add the debug statement below. That will show the information being submitted. Try checking one box in your form and hit submit. echo '<pre>' . print_r($_POST, true) . '</pre>'; Adding the $prod_id, as shown by Barand above, is a good way to determine which checkbox corresponds with the other form fields. <td><input type='checkbox' name='check_list[$prod_id]' value='<?= $prod_id ?>' ></td> <input type='text' name='prod_id[$prod_id]' value='<?= $prod_id ?>' hidden> <input type='text' name='cost_price[$prod_id]' value='<?= $cost_price ?>' hidden> ...