-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Posts posted by cyberRobot
-
-
On 2/2/2024 at 8:04 AM, fanta1066 said:
Ok I am giving up, its far to complicated as I am not a PHP coder. And this has taken up to much of my time.
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); ?>
On 1/31/2024 at 10:15 AM, fanta1066 said:I am using PHP 7.3.1
Side note: the link below shows the PHP versions that are actively being supported.
https://www.php.net/supported-versions -
8 hours ago, Senthilkumar said:
I am getting the following error
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 33554432 bytes)
in file:///C:/Users/senthilkumar.rp/Desktop/Calibration/Calibration/Calibration/Admin/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:209Are 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?
-
31 minutes ago, Barand said:
According to the error message, the relevant file is cell.php.
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);
-
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 -
On 9/20/2023 at 8:31 AM, SLSCoder said:
I need PHP to display error messages but not warning messages.
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.
-
On 7/7/2023 at 8:51 AM, Adamhumbug said:
I believe that it is php 7.3.
Note that you can check with phpversion()
https://www.php.net/manual/en/function.phpversion.phpIn case you're not aware, support for PHP 7.3 ended in December 2021.
https://www.php.net/supported-versions.php -
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_eventAdditional listeners may be available for other events that impact page height.
- 1
-
17 hours ago, jgardonis said:
smart/curly quote vs straight quote looks exactly the same
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'
- 1
-
3 minutes ago, PNewCode said:
Because they are both looking at the actual row instead of just the name that wasn't defined separately? Am I understanding that right?
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.
-
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>';
-
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'; }
-
30 minutes ago, PNewCode said:
yes it's intentional. One is looking to see if the row is empty. The other is using the row for the file name
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.
-
Note that you're using two different variables for the page image ($row["pageimg"] and $pageimg). Is that intentional?
-
2 hours ago, PNewCode said:
Also, I know I have 2 different PHP instances, though it was like that when I got it and I didn't see any reason to mess with it unless I have to since it was semi-working for at least the first entry before.
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.phpAlso, 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) {
-
18 minutes ago, I-AM-OBODO said:
What I am trying to say and mean is that I do not want the form input field to show.
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.
-
5 minutes ago, I-AM-OBODO said:
No other reason. Its just so the value be available for the form. I don't want the table to tags to have form input inside them cos it will make it not look nice. How would you approach it?
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> ...
- 1
-
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> ...
I am well stuck and need help!!!
in PHP Coding Help
Posted
Thanks for the clarification! I removed the line from my post.