Jump to content

Psycho

Moderators
  • Posts

    12,089
  • 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)

572

Reputation

79

Community Answers

  1. Have a table for comments which contains a unique record for each comment/reply: comment_id (id for each comment/reply) post_id (the ID of the post that the comment/reply belongs to) reply_id (The comment Id of the comment being replied to, or empty/0 if it was an initial comment) user_id datetime comment . . . any other relevant info
  2. Here 0is how I would handle that function columninfo($table, $col = NULL) { //State the error condition check if(!$this->CheckTable($table)){ return false; } //State the error condition check if($col!=NULL && !$this->Checkfield($table, $col)){ return false; } //No errors $stmt = $this->db->prepare('SELECT * FROM '.$table); $stmt->execute(); $numCol = $stmt->columnCount(); $colAry = array(); for ($i = 0; $i < $numCol; $i++) { if($stmt->getColumnMeta($i)['name'] == $col) { //Return type for selected column return $stmt->getColumnMeta($i)[0]; } else { //Append current column to return arrray $colAry[] = $stmt->getColumnMeta($i); } } //Return array for all columns return $colAry; }
  3. Generally, I would agree with that. However, I wonder if there would be legal reasons for keeping a copy of the invoice that was sent. Yes, another copy could be generated later and would be the same - if the code had not changed. But, if there was any type of legal action and the company needed to provide records of the invoices that were sent, I don't know if regenerating a copy would be adequate. They might have to also prove that none of the code changed that generated the invoice and if the code had changed they might have to prove what the invoice would have looked like at the time it was generated previously.
  4. Most definitely different character sets (aka fonts). You can tell by the lower case L's in the variable name:
  5. 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 }
  6. 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;
  7. 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.
  8. 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.
  9. 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.
  10. 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 }
  11. 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"; }
  12. 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.
  13. 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)
  14. 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.
  15. @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.
×
×
  • 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.