Jump to content

Psycho

Moderators
  • Posts

    12,086
  • Joined

  • Last visited

  • Days Won

    120

Everything posted by Psycho

  1. Most definitely different character sets (aka fonts). You can tell by the lower case L's in the variable name:
  2. I'll add to @requinix's response. As he said, the easiest approach would be to have a save button that loops through all the rows in the table (except the header) and executes the save individually. Your current save operation only requires an id value. So, I would leave the current save_row() functiona unchanged and then do two things: In the script that builds the table, create a hidden field with the value being the ID Create a new function [e.g. save_all()]. Have that function iterate through every row in the table and get the ID value and execute the save_row() function However, as he said if you have "lots" of rows, this may not be a good approach because each AJAX call would have to be performed separately. You would have to do some testing with the maximum number of records you expect to have to see if it will be an issue. If so, I would take a different approach. I would make the values in the rows actual input fields - making the field names an array. Something like: echo "<input type='text' name='records[{$row_coun_fin['PRODUCT']}][remarks_val]' value='{$row_coun_fin['REMARKS'];}'>"; Then you can submit the whole form via a normal POST or via AJAX. Then the receiving page would just need to iterate over the $_POST['records'] array foreach($_POST['records'] as $productID => $productData) { //Update the data for the current record from the values in $productData }
  3. You are making things harder than they need to be. Why are you including the sales_order table in your query when you don't use any data from that table and you can use the lookup value on the sales_order_lines table? Why do you iterate through the DB results to put them into other arrays just to iterate over those? $sql="SELECT `name`, `quantity`, `delivery_date`, DATE_ADD(`delivery_date`, INTERVAL 10 DAY) AS used_day FROM `sales_orders` so INNER JOIN `sales_order_lines` sol WHERE sol.`parent_id` IS NULL AND sales_orders_id = '$id'"; $result = mysqli_query($connect, $sql); $degree = "STORAGE: KEEP REFRIGERATED BELOW 5`C"; //var_dump($degree); $labels = ""; while($row = mysqli_fetch_array($result)) { $curent_label = sprintf( "%s\n%s %s\n%s %s\n%s\n%s", "{$row['name']}","<br>", 'Delivery Date', "<br>", 'Use By Date', "<br>", "{$row['delivery_date']}","<br>", "{$row['used_day']}","<br>", 'PRODUCT OF SOUTH AFRICA',"<br>", "{$degree}" ); $labels .= str_repeat($curent_label, $row['quantity']) } echo $labels;
  4. Adding a try/catch or die to every single place that an error could potentially occur would probably be an exercise in futility. You say that your shared server has no error logs. You could try adding code to your page(s) to generate an error log. Put this code somewhere so that it will be executed on any page load: ini_set("log_errors", 1); ini_set("error_log", "php-errors.log"); You could then have a separate bowser window open to the location of the error log and refresh it upon any page load to see what errors may have occurred.
  5. With a web application, you can certainly record when a user logs in, but even if you have a logout function a user can simply close the browser window. So, you do need a way to track that they are still there. Since this is a game where two people are playing each other, I think you need to do more than just track when they hit a new page. Here is what I would do: Create a last active field in the user table. Every time you see activity from the user, update the timestamp. Determine "how long" of a time period that you would consider someone as still active: 5 minutes, 10 minutes, ??? Then use that time period to query for active players based on those whose last active timestamp is within the last X minutes. This can also be used for two players already in a game to notify one that the other has dropped off. Once two users start a game use AJAX to both continually update their last active value AND to proactively notify them of anything relevant. E.g. when it is their turn, if the other user drops off, etc. AJAX is simply javascript that makes a server call and returns back data to the user which you can then implement additional logic to act on that returned data. You can update the content in their browser window based on the move the other player made, make a notification, whatever. In this case, I would have the AJAX make a call every X seconds (10, 20, 30 ???). That call would do several things: Update the last active timestamp for the user Check if the other user is still active. Since the other player will also have AJAX running, their last active timestamp should never be greater than the time you set for the AJAX calls to be made. So, if the other players last active timestamp is more than double that time period, I would let the user know that the other user has dropped Check if the other user has made a move (if it was their turn). If so, alert the user that the other user has made their move, show the results of that move, and tell the player it is now their turn. I'm sure there are some things I am leaving out, but the core of it is to use regular calls via AJAX to determine when users have completed a turn and to ensure they are still online. Be sure to use a JavaScript framework to do this (such as JQuery) instead of trying to build the AJAX code with native JavaScript.
  6. It's been at least a decade since I played around with the getid3 library. I'll be honest, I have no idea what ETCO tag data is. But, I have a possible solution. Do you have a file with existing ETCO tags or is there a tag editing application that you can use to set such tags? If you have a file with example tag data that you know what it represents, then instead of using getid3 to set the data, use it to get the data. You can then see what the format of the data is that it expects. I remember doing something similar for some other tag information at the time.
  7. while($cash_on_hand <= 35) Well, that loop is not set up per your instructions. You declared $cash_on_hand twice then in the while condition you hard coded the value (35) instead of using the variable. That loop will run infinitely because $cash_on_hand will always equal 35. You need to calculate $cost on each iteration of the loop and compare that to $cash_on_hand. To be honest, I don't like the instructions given because they require you to define the calculation for $cost at least twice (you should never write code twice - write it once and call it many times). $cash_on_hand = 35; $meal = 25; $tip_percent = 10 $cost = $meal + $meal * ($tip_percent / 100); $cash_on_hand = 35; //Remove this while($cash_on_hand <= 35) { //Fix this to test the condition in the instructions echo "I can afford a tip of $tip_percent%, for Total Cost: $cost <br/>"; $tip_percent++; //Add a recalculation of $cost here }
  8. No way to tell from the code provided as to why you are getting a blank page. That code produces no output. It attempts to set a header value and then redirects to another page. I say "attempts" because I don't see any code where you actually start a session before trying to save a session value. Part of coding is learning to debug. Rather than assuming your code works and redirecting to another page, try outputting to the page for BOTH the success condition and the error conditions. Then, based on those results you can then ad the additional code to redirect or whatever you want. What does the following output? if ($result) { //$_SESSION['messages'][] = 'Thanks for registering. Check your email to confirm your email'; //header('Location: register.php'); //exit; echo "Success saving record with the following values:<br>\n"; echo "usernamebox: '{$data['usernamebox']}'<br>\n"; echo "emailbox: '{$data['emailbox']}'<br>\n"; echo "passwordbox: '{$data['passwordbox']}'<br>\n"; } else { echo "Error attempting to save record with the following values:<br>\n"; echo "usernamebox: '{$data['usernamebox']}'<br>\n"; echo "emailbox: '{$data['emailbox']}'<br>\n"; echo "passwordbox: '{$data['passwordbox']}'<br>\n"; }
  9. I would also highly recommend not referencing database results based on the numeric index and instead referencing results based on an associative array (i.e. named indexes based on the field names). It makes for more readable code and is much, much easier to maintain. The sample code by Barand uses such an implementation.
  10. Not sure if this is the cause of your problem, but your UPDATE query is using the email address in the WHERE calus to determine which record to update AND it is attempting to overwrite the email address. I see no reason why that wouldn't work, but why would you do that? In any event, MySQL has you covered with the INSERT ... ON DUPLICATE KEY UPDATE Statement. Such a statement will attempt to insert a new record But, if the insert would fail because of a duplicate key (e.g. $stdEmail) then the statement will update the current record based on the conditions provided. No need for an initial query to see if the record exists - just run the ONE query. INSERT INTO semakan_dokumen (email, surat_tawaran, ic, sijil_lahir, sijil_spm, sijil_sekolah, sijil_dip, sej_julai, bm_julai, muet, mid1, yuran, umpa_bend1, umpa_bend2, bpkp, penaja, kesihatan, jhepa) VALUES ('$stdEmail', '$fileName', '$fileName1', '$fileName2', '$fileName3', '$fileName4', '$fileName5', '$fileName6', '$fileName7', '$fileName8', '$fileName9', '$fileName10', '$fileName11', '$fileName12', '$fileName13', '$fileName14', '$fileName15', '$fileName16') ON DUPLICATE KEY UPDATE student_id = '$noMatrik' surat_tawaran = VALUES(surat_tawaran), ic = VALUES(ic), sijil_lahir = VALUES(sijil_lahir), sijil_spm = VALUES(sijil_spm), sijil_sekolah = VALUES(sijil_sekolah), sijil_dip = VALUES(sijil_dip), sej_julai = VALUES(sej_julai), bm_julai = VALUES(bm_julai), muet = VALUES(muet), mid1 = VALUES(mid1), yuran = VALUES(yuran), umpa_bend1 = VALUES(umpa_bend1), umpa_bend2 = VALUES(umpa_bend2), bpkp = VALUES(bpkp), penaja = VALUES(penaja), kesihatan = VALUES(kesihatan), jhepa = VALUES(jhepa)
  11. You forgot the next line. The full bit of code you had is if (isset($_POST['submit'])){ //if form submitted $ppp=$_POST['ppp']; //assign value from select box }else{ $ppp=15; //default number of posts-per-page } $_SESSION['ppp']=$ppp; //session index created with new number of posts-per-page If there is no POST submit, then $ppp is set to the default of 15. Then, the last line, is setting the session value to that same default of 15. It NEVER checks to see if there is an existing session value. It will simply overwrite any previous session value. The code needs to work in this manner: Check if the user submitted a new ppp value. If so, set the 'working' value in the script and set the session value If not #1, check if there is a saved session value. If so, set the 'working' value in the script If not #1 or #2, use a default. In the code I provided, I set the default first and let the logic for #1 and #2 overwrite the default. I don't know why the code is not working for you. There is obviously something in the code that you have not provided. But, here are some other comments: Why are you checking for $_POST['submit']? You only need to check for $_POST['ppp'], since that is the value you would be working with As Barand stated, and I alluded to, NEVER trust data from the user. It is a trivial matter to pass a value that is not in a select list for a form field, to add other field value in a form request, remove others, pass values that would have been validated on the client-side, etc. For a select list, I suggest having a defined list (such as an array in a config file) and use that list to a) Create the select list and b) validate that the user passed an approved value. So, put the code to check for a POST ppp value, or a session ppp value or to use a default at the top of the script before you need the ppp value. Not sure why this is a question.
  12. @dunno You start by referring to page1 (the form page) and page2 (the page to shows the posts per page). But, in response to Barand's reply you show the code where the session value is set, but don't explain where that code is run. Is that code on page1, page2, or some other page? If that code is executed on every execution of page2, then it will reset the ppp value to 15 whenever the user doesn't select a new ppp value since you are ALWAYS resetting the session value - even when the user did not submit a change. If that code is on an intermediary page (a third script) - is session_start() initiated on that page? EDIT: I'm going to assume that the code to set the ppp session value based on the user's submission is at the top of the script that displays the posts. In that case, you should change the logic like this: //Set list of APPROVED ppp values (prevents users from submitting arbitrary vaues) $pppValues = array(10, 15, 20, 50, 100); //This array should be in a config file and ALSO used to create the select list options //Set default value of $ppp value $ppp = 15; //Check if user submitted new ppp value (that is in approved list) if (isset($_POST['ppp']) && in_array($_POST['ppp'], $pppValues)) { $ppp = $_POST['ppp']; //Assign value from POST submission $_SESSION['ppp']=$ppp; //Set value in session (only set if user submitted new value) } //If user did not submit new ppp value, check if ppp value already set in session elseif (isset($_SESSION['ppp']) { $ppp = $_SESSION['ppp']; //Assign value from session } //Rest of script can use $ppp to display correct number of posts @Strider64 Not sure what you mean. Session values are a common process of keeping values static between page loads. No need to store the value in a config value.
  13. I'm assuming the issue is within the class "BaseController". Is that where the methods load and library are defined? It would seem to me that the call to 'load' is returning null instead of an object, which causes the error when the 'library' method is called.
  14. So, as I understand it, the user is adding multiple line items for an invoice and THEN you redirect at the end. Why? Here is what I suggest you do. User navigates to a CREATE_INVOICE page On first entry there will be no GET value for the invoice ID, so display whatever initial instructions/content to be displayed to the user. E.g. it could provide a form for vendor name/address, PO number, etc. User submits the form using POST The receiving page identifies that this is a new invoice and add the applicable header records to the DB and generates an invoice ID The receiving page then performs a redirect to the CREATE_INVOICE page with a GET value for the invoice ID The CREATE_INVOICE page detects the invoice ID and displays the current invoice data (including any line items already added), The page also displays a form to add a new line item. The user will have two options. 1) Enter data into the fields for a new line item or 2) Complete the invoice If the user enters a new line item, it sends the form data (using POST) to the processing page which adds the new line item and then performs a redirect using the invoice ID as a GET value. This takes the logic back to step 6 and will repeat indefinitely until the user decides to complete the invoice
  15. 1. Create a function that takes the excel file as an input and performs all the operations you want to do to the excel files 2. Use a process to loop through all the excel files: scandir(), readdir(), . . . ??? 3. Upon each iteration of the loop call the function in step #1 passing the current file as a parameter
  16. Try putting this bit of debugging code in your script right before your if() statement. What does it produce when you run the script? if(!isset($_SESSION)) { echo "Session was not started yet"; } else { echo "Session data:<br>"; echo "<pre>".print_r($_SESSION, true)."</pre>"; }
  17. You really need to analyze the source data to identify the different data and types of issues that can exist in order to determine the appropriate solution. For example, the solution @Barand provided would be acceptable if: 1) The only issues are missing closing tags 2) None of the "data" contains a greater than sign If there are other types of issues or if data can contain the < symbol then a different solution is in order.
  18. To add to @requinix's response, the communication to the database would be between the PHP server and the database server. The client should have no idea about how the connection is made. However, if you have "holes" in your application that allows the users to infiltrate your server-side code, then all bets are off. Unfortunately, the guidance on not creating those holes is an expansive subject. A forum is great for asking abut specific aspects, but for the big picture I would suggest looking for training and/or guides on the subject.
  19. If you are submitting your form to the same page that form is on, it is typically good practice to put the form processing logic at the top of the page. That way if you need to show the results of the new data or show form processing errors you can generate that within the content of the page. I have not run your code, but I notice that the JavaScript that is called from within the action parameter of the form returns false at the end of the script. If you return false within the action parameter of a firm, then the form is never submitted. That may be your problem.
  20. To expand on @Barand's response, how you implement it depends on "how" you want the result to be returned. Are you just wanting a True/False based whether it is a multi-dimensional array, do you want the number of sub-arrays, or what?
  21. Taking a quick look at the source page to be scraped, the page appears to be specifically built to prevent scraping. Specifically, the content (i.e. the winning numbers) is loaded externally and populated on the page dynamically. It doesn't mean it can't be done, but it certainly won't be as trivial as it would seem.
  22. One significant problem with your request is you started out by saying it was a multi-dimensional array when it is , in fact, a flat array. But, your responses have been far from illustrative. Understand that you are very close to the problem and KNOW what is in your head. So, while you think a statement is perfectly obvious, to others it is greek. In any case, if you have an array that you want to "split" into "chunks" of an arbitrary size, PHP has a built-in function to do that: array_chunk() //Input data $outputFile = "output.csv"; $itemsPerLine = 3; $hexCodes = array("ff00ff", "ff00cc", "ff0099", "ff0066", "ff0033", "ff0000", "ff3300", "ff6600", "ff9900", "ffcc00", "ffff00", "ccff00", "99ff00", "66ff00", "33ff00", "00ff00", "00ff33", "00ff66", "00ff99", "00ffcc", "00ffff", "00ccff", "0099ff", "0066ff", "0033ff", "0000ff", "3300ff", "6600ff", "9900ff", "cc00ff", "9900ff", "6600ff", "3300ff", "0000ff", "0033ff", "0066ff", "0099ff", "00ccff", "00ffff", "00ffcc", "00ff99", "00ff66", "00ff33", "00ff00", "33ff00", "66ff00", "99ff00", "ccff00", "ffff00", "ffcc00", "ff9900", "ff6600", "ff3300", "ff0000", "ff0033", "ff0066", "ff0099", "ff00cc", "ff00ff"); //Open file for writing $fileHandle = fopen($outputFile, 'w'); //Split the array into chunks and write each chunk to the file //with a comma separator and a line feed character foreach (array_chunk($hexCodes, $itemsPerLine) as $line) { fwrite($fileHandle, implode(',', $line) . "\n"); } //Close the file fclose($fileHandle); Here is the output ff00ff,ff00cc,ff0099 ff0066,ff0033,ff0000 ff3300,ff6600,ff9900 ffcc00,ffff00,ccff00 99ff00,66ff00,33ff00 00ff00,00ff33,00ff66 00ff99,00ffcc,00ffff 00ccff,0099ff,0066ff 0033ff,0000ff,3300ff 6600ff,9900ff,cc00ff 9900ff,6600ff,3300ff 0000ff,0033ff,0066ff 0099ff,00ccff,00ffff 00ffcc,00ff99,00ff66 00ff33,00ff00,33ff00 66ff00,99ff00,ccff00 ffff00,ffcc00,ff9900 ff6600,ff3300,ff0000 ff0033,ff0066,ff0099 ff00cc,ff00ff EDIT: Or if you want the quote marks and spacing, replace with this line fwrite($fileHandle, '"' . implode('", "', $line) . "\"\n");
  23. 5.5 (i.e. 5:30) * 60 (minutes) * 60 (seconds) = 19800 I assume the 0 represent the first element of the array of timezone within the +5:30 UTC offset - 'Asia/Colombo'. Further, I expect you will ALWAYS get the first timezone corresponding to the UTC offset (as a default) because there is no way that an actual timezone can be specified in the string value you are using. '+05:30' => array ( 0 => 'Asia/Colombo', 1 => 'Asia/Kolkata', ),
  24. Look at the code examples on that page. The examples first create a datetime object with a specific timezone and then use gettimezone to retrieve the timezone that was previously set. A string such as "2021-05-06T13:48:19.2064951+05:30" has only the offset from UTC time - there is no timezone identifier. So, there is no way to programmatically determine the correct timezone out of the ones that share that offset.
  25. No clue. I think this is a JavaScript problem, not a PHP problem. I see the following code with references to "toggle" <a style="text-decoration: none;color: #000;" title="View Details" data-toggle="collapse" data-target="#products-details<?php echo $drow['order_id']; ?>"> <i class="nc-icon nc-minimal-down" onclick="changeToggleIcon(this)"></i> </a> But, those are tags within nothing in them to be displayed to the user. Further the actual javascript functions are not in the above code. If this is indeed a javascript problem, then you shoudl post the HTML that is generated by the PHP code and be sure to include any javascript functions that are called by that code.
×
×
  • 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.