Jump to content

Psycho

Moderators
  • Posts

    12,146
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. Then as we've already described, there must be other code that is doing the insert or the code is being run twice. For example, it could be running once to insert the record, but then does a redirect back to itself and runs the false condition. There is definitely something going on here that is not in the code you have provided. What is in that other function I identified which is being called? fieldsArrayForCreateUpdate()
  2. Good to know. But, with all due respect, what the hell were you even asking in your original post? I've reread it a couple of times and it still doesn't make any sense as to how it applies to what I now understand you were trying to accomplish.
  3. That doesn't sound like anything to do with what you originally asked. Perhaps you need to provide some examples of what you are talking about. But, if your problem is that you need to prevent duplicates with respect to two fields, you can enforce that directly through the DB schema. For example, if you have fields for First Name and Last Name you can set the schema up so that the combination of First name and Last Name are unique. Here is an example: First Name | Last Name ------------------------- David Smith David Andeerson Richard Smith If you set the combination of First Name + Last Name must be unique, all those values would be allowed. But, you could not add another record such as "David Smith"
  4. @new2you, there is nothing in that code that would wipe out the $_POST array, but there is another function call in that function $fields = fieldsArrayForCreateUpdate(); @ginerjm, the code does not have labels within labels. There is only one label. His code is overly complex and utilizes the ternary operator where, in my opinion, makes it more difficult to read. Here is a rewrite that woud do the same thing that is more logical //Since you want the format for the input fields to be the same, //You can create a function to create them function standardInputField($fieldLabel, $fieldName, $fieldValue, $errorsAry) { //Determine label ID and input ID $fieldId = ($fieldName == "new_store_name" || $fieldName == "new_item_name") { $labelID = 'label-new-store-or-item'; $inputID = 'new_store_name'; } else { $labelID = ''; $inputID = 'new_item_name'; } //Determine error message if(isset($errorsAry) && in_array($fieldName, $errorsAry)) { $fields = fieldsArrayForCreateUpdate(); $error .= " <span class='error-message'>{$fields[$fieldName]['error']}</span>\n"; } else { $error = "": } $fieldHTML = "<div class='control-group'>\n"; $fieldHTML .= " <label id='{$labelID}' class='control-label'>{$fieldLabel}</label>\n"; $fieldHTML .= " <div class='controls'>\n"; $fieldHTML .= " <input class='other-store-or-item' id='{$inputID}' type='text' name='{$fieldName}' value='{$fieldValue}' />\n" $fieldHTML .= $error; $fieldHTML .= " </div>\n"; $fieldHTML .= "</div>\n"; return $fieldHTML; }
  5. You first need to use correct terminology. You keep switching back and forth between "object" and "array". Yu are dealing with an object. I know this because the first bit you displayed looks to be from a print_r Then when you tried to use it, incorrectly, in num_rows(), it also told you it was an object Objects have properties and methods. You can see all the properties of the object in the print_r() that you did. Protected properties of a method cannot be accessed directly. They are built this way to prevent manipulation of data that would otherwise create invalid scenarios. Your object apparently represents a DB query result. If you were able to change 'num_rows' then it would not match the results. If there are protected or private properties that are menat to be accessed there should be methods for the object to return that data. I don't know squat about moodle. But, you should be able to find by checking the documentation for it. But, there's a good chance they simply used the same name to retrieve that value. Try: $mysqli_native_moodle_recordset->numrows(); Or ]$mysqli_native_moodle_recordset->num_rows(); If neither works, go check the documentation or post in a forum to get help with 3rd party frameworks.
  6. Not according to PHP object given Where, exactly, are you getting this array/object from?
  7. OK, I agree with ginerjm. You are providing way too much information. This makes it difficult for us to understand what you are asking and then expecting us to read through a bunch of code to try and decipher decreases your chances of getting a response. You need to learn how to reduce the code (and explanation) to what is pertinent. What I understand is that the condition to check if the super global $_POST is empty is not generating the results you think it should. Specifically, you are getting this on the page: Array() There's something wrong somewhere!!! Array() Then, looking at just the relevant code, you have this print_r($_POST); //##### if ( !empty($_POST)) { // keep track of $_POST(ed) values by storing the entered values to memory variables $store_id = $_POST['store_id']; $item_id = $_POST['item_id']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; // . . . // . . . $sql = "INSERT INTO shoplist (store_id,item_id,qty_pkg,pkg_of,price,flyer_page,limited_time_sale,flyer_date_start,nos_to_purchase,section_id,shopper1_buy_flag,shopper2_buy_flag,purchased_flag,purchase_later_flag,no_flag_set) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $q = $pdo->prepare($sql); $q->execute(array($store_id,$item_id,$qty_pkg,$pkg_of,$price,$flyer_page,$limited_time_sale,$flyerDateStart,$nos_to_purchase,$section_id,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_Y)); } else { echo "<br />There's something wrong somewhere!!!<br />"; //##### print_r ($_POST); //##### // . . . The ones I commented with "#####" are the ones producing the output. So, that tells me that $_POST is empty. But, you say that a record is getting created based on the code in the TRUE part of the conditional block. That is impossible based on what you posted. Either this isn't the right code, there is other code that isn't being displayed, or you are misinterpreting the results. To verify, just add some additional debugging logic echo "Count of $_POST var: " . count($_POST) . "<br>\n"; if ( !empty($_POST)) { echo "Starting the code block for the TRUE condition<br>"; // keep track of $_POST(ed) values by storing the entered values to memory variables $store_id = $_POST['store_id']; $item_id = $_POST['item_id']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; // . . . // . . . $sql = "INSERT INTO shoplist (store_id,item_id,qty_pkg,pkg_of,price,flyer_page,limited_time_sale,flyer_date_start,nos_to_purchase,section_id,shopper1_buy_flag,shopper2_buy_flag,purchased_flag,purchase_later_flag,no_flag_set) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $q = $pdo->prepare($sql); $q->execute(array($store_id,$item_id,$qty_pkg,$pkg_of,$price,$flyer_page,$limited_time_sale,$flyerDateStart,$nos_to_purchase,$section_id,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_Y)); echo "Executed SQL query: $sql<br>"; } else { echo "Starting the code block for the FALSE condition<br>"; echo "<br />There's something wrong somewhere!!!<br />"; print_r ($_POST); // . . .
  8. Those values are "protected". That means you cannot access them in that way (http://php.net/manual/en/language.oop5.visibility.php). I don't know why you would be trying to do that anyway. You have an object. You need to understand the methods that the object provides. You're apparently using mysqli, so why not just use the mysqli_ method to get the number of rows? http://us1.php.net/manual/en/mysqli-result.num-rows.php
  9. Sounds like a character encoding problem. Take a look at this thread http://forums.phpfreaks.com/topic/290726-character-encoding-problem-got-strange-characters-in-my-database/?hl=%2Butf+%2Bdatabase&do=findComment&comment=1489348
  10. Sorry, I didn't pay attention, I thought you were calling a custom method. If you want you can change the file name in the php.ini file. But, what does it matter what extension it has? Put a txt or log on there if you wish.
  11. As mac_gyver stated, it is closed automatically when it is done executing all the pages needed for the request. It is not when it encounters a ?>. You can reuse that request across any of the pages used on that request. Another thought to your original problem. Are you using any AJAX on your pages? If so, there could be multiple requests made to the server while a user is watching a video.
  12. If it is working for you then, yes, that is what I mean. I can't comment on the error log file name. You appear to be using a class for your error logging. You would have to look at the code that creates that file to change it to something else - if that is what you want to do.
  13. Not sure I follow you. getTimezoneOffset() returns the difference between the user's timzone and UTC. You must live in a timezone the same as UTC. Are you wanting to translate that into a textual description of the timezone? E.g. PST (Pacific Standard Time)? If so, you would have to create a dictionary of all the possible values. But, it would not be 'accurate' since multiple users can have the same "time" (and UTC offset) but be in different timezones.
  14. There is no way for us to know. How are $salt, $ip, and $formName defined? If they are the same, then the resulting hash will be the same.
  15. I have a lot of experience with generating PDFs ia a web interface, but this was with the use of custom PostScript files and a backend processor. This would be well outside what you are looking to do. You'll need to run the output through an additional process to make it a PDF. There is built-in PDF handling in PHP (http://php.net/manual/en/book.pdf.php), but I don't think it is the easiest to work with. Fo rexample, you can't just send the output for PDF, you basically have to tell the code where to put each piece of information. For example, for the first line you would provide code to set the position on the page, set the font to use, the color of the font, and then pass the text to output. Then you would set the position for the 2nd line and send the text for that line. Unless you are going to build your own PDF framework, I don't think it is worth your time. However, there are plenty of other frameworks/classes that are available which would be easier. I don't have on to suggest though. Alternatively, there are also applications out there that allow you to prepare a "page" using HTML and then pass that output to an application that will generate it into a PDF. Most of these (at least the ones that do a good job) cost money. Here are a couple resources you can take a look at to see if any meet your needs: http://www.tcpdf.org/ http://www.fpdf.org/ http://mpdf.bpm1.com/
  16. If you really want it exactly as it is returned with the exception of the part in parenthesis, then just use a string manipulation to only get the first part. You need to convert it to a string first. var visitors_time = new Date().toString(); var displayDate = visitors_time.substr(0, visitors_time.indexOf('(')-1);
  17. Set up the table in the database so that the column is UNIQUE. The database will then actively prevent a duplicate from being created. But, it will generate an error, so you need to check for any error and then for the specific error of a duplicate constraint. You're mixing mysql_ and mysqli_ in your code. You should either use mysqli_ or PDO. Here is a quick example of how the code might look with PDO: // Assumes PDO DB connection was made with $db // being the instance of that connection //Create the prepared INSERT statement $sql = "INSERT INTO table (message) VALUES (:message)"; $stmt = $db->prepare($sql); //Associate data with an array for the prepared statement $data = array('message' => $_POST[message]); //Try to execute the INSERT statement try { $stmt->execute($data); //Set default message assuming this completed $error = "This message does not exist. Insert it!!!"; } catch (PDOException $stmt_error) { //check the error code if ($stmt_error->errorInfo[1] == 1062) { //Error was due to a duplicate exception $error = "Message Exists."; } else { //Error was due to some other issue $error = "An error occured."; } }
  18. Then, didn't you just answer your own question? Although, having a keyword for "rugby" and then another for "rugby league" seems odd. I think you're making it too specific. If "rugby" is a keyword on its own, why do you need "rugby league"?
  19. Mac_gyver has provided a solid solution that you should consider. But, there is a simple 'hack' to get you a workable solution in the short run. If an error is encountered, first check the modified date of the log file. If it is more than N minutes since it was last modified, send the email. Otherwise do not send the email But, in either case you would still log the error. The result is that once you start getting errors you will get an email. But, you would not get another email from any failures unless there were no errors for the given amount of time.
  20. brown2005, you need to help us out here. You need to be specific and provide clear details. Giving a general response such as that doesn't help to provide clarity. For example, I don't fully understand how you created the three tables and what the association between them are. It appears the "domains" table holds the domains and their info. Then it appears the "words" table holds the actual keywords. So, I will *assume* the "keywords" table records contain a foreign key reference between the domains and words tables. But, I don't know how you "USE" those values and what you expected results are. I would expect that you would want one entry for "rugby" and one for "league". I don't see any need to create a specific association for the concatenated "rugby league". But, since I don't know how you implemented the keyword checks or how "rugby league" would not work with just the single words, I can't provide any guidance.
  21. That is impossible to answer without understanding how the data is used.
  22. A few more comments: Your logic is to prevent the insertion of a record with a duplicate "message" content. But, you are doing a "SELECT *". There is no need to select data for this, plus it is inefficient. You could just SELECT COUNT(*) and check that the value is not zero or just select a single field with a LIMIT of 1 and check the count. Both would be better options that SELECT * on all the records. Second, if you really want to prevent duplicates that is a poor approach. A "race condition" could cause duplicates to be created - i.e. when the select is run the duplicate does not exist, but by the time the INSERT is run the duplicate would exist. If you really want to prevent duplicates then set the field as "unique" within the database. This will absolutely prevent duplicates. Then you could just run the INSERT query only. If there is an error from the query you can check if it was due to a duplicate constraint. Lastly, checking for a duplicate on a 'message' value seems a little odd. Are you doing this to prevent an issue with people accidentally double posting? This could be due to a poor design in the actual posting logic allowing people to do a page refresh that was causing the double postings. There are better ways to prevent this, such as doing a redirect right after the post data is processed.
  23. Why do you have this //include connect.php page for database connection include('connect.php'); The code that appears before this is already connecting to the DB and selecting the DB. If you look at the logic of your page, there are conditions for which there is no handling. For example: if($_SERVER['POST_METHOD'] == 'POST') There is no else condition for this condition, which means if that condition is not true - nothing will happen. What is "POST_METHOD"? There is no such index for the $_SERVER super global. So, unless you defined that variable - it does not exist. I think you meant to use REQUEST_METHOD There is more wrong with this code as well. 1. You use the $_POST values to verify the input data - then use $_REQUEST for the value in the query 2. The code uses mysql_ functions which are deprecated 3. The code is open to SQL injection
  24. Try SELECT p.player_id, p.player_first_name, p.player_last_name, v.player_height, v.player_weight FROM players p LEFT JOIN player_vitals v ON p.player_id = v.player_id AND v.vital_id IN (SELECT MAX(vital_id) FROM player_vitals GROUP BY player_id) LEFT JOIN teams c using (team_id) ORDER BY p.player_last_name, p.player_first_name
×
×
  • 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.