Jump to content

Psycho

Moderators
  • Posts

    12,081
  • Joined

  • Last visited

  • Days Won

    120

Psycho last won the day on September 24 2020

Psycho had the most liked content!

About Psycho

Profile Information

  • Gender
    Not Telling
  • Location
    Canada

Recent Profile Visitors

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

Psycho's Achievements

Prolific Member

Prolific Member (5/5)

571

Reputation

78

Community Answers

  1. 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.
  2. 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 }
  3. 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"; }
  4. 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.
  5. 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)
  6. 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.
  7. @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.
  8. 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.
  9. 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
  10. 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
  11. 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>"; }
  12. 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.
  13. 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.
  14. 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.
  15. 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?
×
×
  • 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.