Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Hard to say since you didn't post any code. But, the calculation you posted above is wrong for TWO reason: 1. You have to use parenthesis to ensure the calculations are completed in the order you expect. Otherwise the normal order of operations will take precedence. So, it would be calualted as follows: $payment = $asking + ($doc x $tax) - ($down x $interest / $term) I think you want something like this $payment = (((($asking + $doc) x $tax) - $down) x $interest) / $term However, that is also wrong. You cannot calculate interest across multiple multiple payments like that because the interest is not calculated up front. The interest is calculated each period. So, if the payments are monthly 1/12 of the interest is calculated against the remaining balance each month. The calculations uses some more advanced math. Go do a google search on calculating loan payments to get the correct formula EDIT: Your signature also makes no sense What would be the significance of displaying your ring finger. I think you meant it to be the middle finger, in which case, it would be id = 2. "There are 10 types of people in the world. Those who understand binary and those who don't"
-
http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059
- 8 replies
-
- sql injection
- mysql_real_escape_string()
-
(and 1 more)
Tagged with:
-
PDO is an alternative driver for working with databases. So, all the code you have now that uses "mysql_" functions would be replaced - in some fashion. It isn't going to be a drop-in replacement. You'll need to take a little time to learn how to use prepared statements which is one of the huge benefits of using PDO. The mysqli_ drivers have prepared statements as well, but aren't as easy (in my opinion). Plus, the PDO drivers are compatible with different types of databases - but just MySQL.
- 8 replies
-
- sql injection
- mysql_real_escape_string()
-
(and 1 more)
Tagged with:
-
Help get values of total addition and total substraction
Psycho replied to lovephp's topic in Javascript Help
Then don't put the output into LABELs and instead put them into read-only input fields. If you don't want them to "look" like input fields then remove the border via CSS: http://jsfiddle.net/KXGEY/12/ But . . . why would you need to do this? You should NOT be passing the calculated values in your POST data. You should recalculate on the server-side. Never trust any input coming from the user. They can manipulate anything on the form. -
Help get values of total addition and total substraction
Psycho replied to lovephp's topic in Javascript Help
Both the addition and subtraction 'appear' to be working correctly for me. But, again, you have not stated any problem. If your problem is important enough that you need a resolution, at least take the time to adequately explain what it is you are trying to accomplish, what problem you are having (e.g. what isn't working correct and any errors you are getting), and what you have tried thus far to resolve and the results. $(function() { $(document).on('blur keyup', '.add, .sub', function(e) { var add = 0; var sub = 0; var sum = 0; $('.add').each(function(i) { if (!isNaN(this.value) && this.value.length != 0) { add += parseFloat(this.value); } }); $('.sub').each(function(i) { if (!isNaN(this.value) && this.value.length != 0) { sub += parseFloat(this.value); } }); sum = add - sub; $('#totaladd').text(add.toFixed(1)); $('#totalsub').text(sub.toFixed(1)); $('#total').text(sum.toFixed(2)); }) }) -
Here's an example of how you can extract the content between the two tags then replace it with modified content (which is what I think you are trying to do): $content = "This is content with [A_CUSTOM]bold[\A_CUSTOM] and [A_CUSTOM_TAG]italic[\A_CUSTOM_TAG] text"; $custom_tag_array = array( 'A_CUSTOM' => '<b>\\1</b>', 'A_CUSTOM_TAG' => '<i>\\1</i>' ); foreach($custom_tag_array as $tag => $replacement) { $pattern = "#\[{$tag}\](.*?)\[\\\\{$tag}\]#"; $content = preg_replace($pattern, $replacement, $content); } echo $content; Output This is content with <b>bold</b> and <i>italic</i> text
-
That is very different from what you previously posted. I don't recall anything about opening and closing tags. Your example only showed a single placeholder tag that was being replaced. Plus, your closing patter has no delimiters. And, your code (as shown above) won't match anything. Your tags in the array already have "A_", but then you are appending another "A_" when creating the pattern. If you have opening and closing tags, then I'm really not sure what you are trying to accomplish. Are you trying to create your own BBCode type parser where the content between the tags will be modified? By only giving us partial and/or erroneous information we are going to waste our time.
-
Help get values of total addition and total substraction
Psycho replied to lovephp's topic in Javascript Help
Do you have a question? -
I can't even venture a guess based on the little information provided. The problem is you have an idea in your head which includes a lot of functionality that either you assume to be included or which you have not thought through yet. If someone does give you a quote based upon just the information above you will want to triple or quadruple it to determine what the real cost will be. Because, you will start including additional requirements that are needed that weren't included in the quote. You should still look into existing modules. You might find something that is close enough to what you need to get started. Then you might be able to find someone to add the modifications that you want. But, I would not be interested anyway. I wouldn't have the time or interest. Good luck.
-
What I need to be able to do is query the number of bugs that each program has but also query it for each script/program. Huh? Per your table you have only one column to store 'name(of a program/script)'. I don't see how you can get information for scripts within a program. Or maybe you are just not describing it accurately. Plus, your query is doing a count of a field called 'bug' which doesn't exist based on your description. If you just want count by unique values in the 'name' column, use this: SELECT name, COUNT(id) AS bug_count FROM bugs GROUP BY name
-
I don't see any issues either. Perhaps you are looking at a different file than the one that is actually being run or something else where the code you are looking at is not the code that is being executed (it's happened to all of us). Or, if you had a bug and fixed it, perhaps the page is showing the previous cached results. Anyway, once you find your problem, you can remove the multiple lines of code by utilizing arrays for the search and replacement values. If you have a lot of these it will be much easier to manage this way $replacements = array( '[A_CUSTOM]' => 'I have a and custom', '[A_CUSTOM_TAG]' => 'I have a, custom and tag' ); $content = 'Here is some text and [A_CUSTOM]. Here is more text and [A_CUSTOM_TAG]'. $content = str_replace(array_keys($replacements), $replacements, $content);
-
Sure, you can go look at some shopping cart apps. Each will be different based upon the user experience, payment options and how much they can be modified to fit your needs. But, they are not buying a 'product', they are buying permission to see the additional information. So, you would need additional functionality to incorporate that capability - which would not be included in most (if any) pre-made shopping cart applications. I suggest you do some research to see if any do meet your needs. If not, post in the freelance forum to see if someone would be willing to give you a quote. But, you would need to provide A LOT more information about all the requirements to get an appropriate cost. I think it will be a lot more than you think it will be.
-
So, what are you really asking? Your follow up states you need a sign-up script. And??? Are you wanting us to provide that to you? As for how would they pay for seeing the additional info, that's more of a usability question. Would they be purchasing on a site-by-site basis, would you provide a subscription to see unlimited or a certain number of sites within a month or other time period? Maybe you want to allow them to select properties to view and them bill them at the end of the month. Those are all business decisions to be decided before you consider how to accomplish it programatically. However, I don't see how this would work. From my experience the selling Agent will typically make as much information about the properties they are selling publicly available in order to get potential buyers. Why would a buying agent go to your site to buy the information that they can already get for free?
-
Cloak and Track a Link when using a variable url
Psycho replied to vistavision's topic in PHP Coding Help
Let's assume your links are stored in a table with an ID, the URL and a Text description. You can create your links like this: echo "<a href='affiliate.php?id={$row['id']}'>{$row['text']}</a>'; Then create a page for affiliate.php. On that page you would take the ID passed on the query string and run a query to get the URL. Then you can do whatever logging of the click that you want to perform. Lastly, you would use a header() function to redirect the user to the URL. -
File IDS saved as numbers. if ID 1 exists, set path to ID 2
Psycho replied to mikk809h's topic in PHP Coding Help
Sorry, no. That really isn't any more clear. You seem to be asking about a lot of different things and I'm really not sure what the problem is that you are trying to solve via this post. I have a feeling you are making something overly complicated. Anyway, here are some 'ideas' based upon what you have stated above. Creating a new session: You have a variable for method that will tell you when to start a new session. To start a new session you can use session_regenerate_id() to create a new session ID. Then use session_id() to get the id for that session. You can then use that to create the folder. Note: You should probably go ahead and have session_start() on the page by default. That means a session will be automatically created even before you detect the 'startSession' - that session would just get thrown away and unused. Then, whenever you need to save a file, use the session id to dynamically determine the folder path. However, I'm not sure, but I think you might run into problems trying to submit files using the GET method. I would suggest using POST. -
File IDS saved as numbers. if ID 1 exists, set path to ID 2
Psycho replied to mikk809h's topic in PHP Coding Help
Your request is not very clear. What is the "post data" and the "auth key" and how are they related to the upload process? From your example, it appears you are wanting to check if the file being uploaded already exists in the target folder and, if so, upload the file to a different folder. But, really that is only a guess because I really don't understand most of what you posted. -
embed pdf in page but need html to be on the page also
Psycho replied to accend's topic in PHP Coding Help
You could try loading the PDF in a frame. Although I despise frames. -
Help required to fully and properly parameterize a SELECT query
Psycho replied to excelmaster's topic in PHP Coding Help
@Jacques: If 0 is a possible value, then using intval() is a bad idea. But, in almost all cases I am using it for values related to an auto-increment field which begins with 1. I guess my point is not so much about the use of intval() so much as it can be appropriate to perform a validation/sanitization of the submitted values instead of just relying upon the parametization in the query. It all depends on the use case. So, intval() could be replaced with an appropriate process for the validation as needed. -
Comparing Two Arrays and Merging Values That Are a Near Match
Psycho replied to mkc's topic in PHP Coding Help
Without being able to inspect the data myself, no. I created two tables with the fields referenced above and actually tested this: both the SELECT and the UPDATE and both worked. If you remove the WHERE portion of the query, are any records returned? If no, then the problem is with the JOIN. If you do get results, the problem is with the WHERE condition. -
You should not store duplicate data in multiple tables. They are called relational databases because you can relate data between tables. That's the whole point of having associations between tables. If the "code" can be changed each time the test is taken, then the code belongs to the "test" not to the questions or the answers. I would think you need three tables: the question table which holds just the questions and the data associated with the questions. E.g. question_id (primary key), question_number and question_text Then for each "adventure" you would record in TWO tables. One table would just be to record the basics of the adventure, including the code (without the answers). It could look like that Table: adventures adventure_id (primary key), user_id (foreign key), adventure_date, code Then, you would record the users answers for each adventure in a third table. An example: adventure_answers: answer_id (primary key) adventure_id (foreign key) question_id (foreign key) answer_id (foreign key - assume there is answer table)
-
Comparing Two Arrays and Merging Values That Are a Near Match
Psycho replied to mkc's topic in PHP Coding Help
OK, apparently cleints-old will not work in that query because of the dash. You need to enclose the field name in back ticks. SELECT c.firstname, c.surname, c.phone AS current_phone, o.phone AS original_phone FROM clients c JOIN `clients-old` o ON c.firstname = o.firstname AND c.surname = o.surname WHERE LEFT(o.phone, LENGTH(c.phone)) = c.phone AND LENGTH(c.phone) < 10 Anyway, once you've found the right WHERE condition to include just the records to be updated, you would modify the query to perform the actual update like so UPDATE clients c JOIN `clients-old` o ON c.firstname = o.firstname AND c.surname = o.surname SET c.phone = o.phone WHERE LEFT(o.phone, LENGTH(c.phone)) = c.phone AND LENGTH(c.phone) < 10 -
Comparing Two Arrays and Merging Values That Are a Near Match
Psycho replied to mkc's topic in PHP Coding Help
Try the following SELECT query to see if it is pulling the records you think should be updated. The query first JOINs the records between the two tables where both the firstname and surname are the same. Then, the WHERE clause keeps those where the value of the current phone is matches the first part of the original phone. Plus, the length of the current phone must be less than 10 characters. SELECT c.firstname, c.surname, c.phone AS current_phone, o.phone AS original_phone FROM clients c JOIN clients-old o ON c.firstname = o.firstname AND c.surname = o.surname WHERE LEFT(o.phone, LENGTH(c.phone)) = c.phone AND LENGTH(c.phone) < 10 Alternatively, you can change the WHERE clause to this WHERE LEFT(o.phone, LENGTH(c.phone)) = c.phone AND LENGTH(c.phone) < LENGTH(o.phone) In this case the value of the current phone must match the beginning of the original phone and it must have less characters. Without seeing the data, I can't say what the optimal method is for getting the right records. Once we have the appropriate SELECT query, we can modify it to do an UPDATE instead. EDIT: changed WHERE clause to look for values less than 10 digits (since the cut off values are 9) -
Comparing Two Arrays and Merging Values That Are a Near Match
Psycho replied to mkc's topic in PHP Coding Help
And can you provide the details of how the phone numbers are stored? What are the field types? Are they stored with formatting (e.g. (123) 456-7890), etc. Exactly how many characters are the ones that are cut off? -
Help required to fully and properly parameterize a SELECT query
Psycho replied to excelmaster's topic in PHP Coding Help
I use this approach all the time //Force all passed IDs to be integers and filter out 0/empty values $IDnumbersAry = array_filter(array_map('intval', $_POST['IDnumber'])); There is zero difference in the results of doing this than in adding all the values as parametized values in the query. however, with respect to the rest of the code, you have a check to see if the array contains any values before running the query. But, that check is buried under two switch statements and an if(). Assuming all the logic under those two switch statements require this array of values, you could do that check first. I'll add one last comment. I typically wrap my queries within functions or methods. The sanitizing of the input data would typically occur before the function/method is called. But, I don't want to risk passing potentially unsafe values to the function/method at some later point. So it would make sense to parametize the values anyway. I just prefer to run intval/array_filter before that so I can implement and error handling/messaging to the user. -
Comparing Two Arrays and Merging Values That Are a Near Match
Psycho replied to mkc's topic in PHP Coding Help
Just to be sure we aren't taking the long road, I have a question. Why not just update the phone numbers without the comparison. Now, I *think* what may be the issue is that you have the original DB and the current DB - and that the current DB has since been modified: phone numbers added, edited, deleted. So, you may just be wanting to correct those phone numbers which were copied from the original DB and cut off. Can you confirm if that is the case or what the situation is? That might help to create an easier solution. Second, we might not have to query the two databases, dump the results into arrays, process the arrays, and then update the database. This might be able to be handled direction through a query or two. Please provide details about the two tables along with the relevant fields. For example, what fields are used to determine that it is the same record, what is the format of the phone number data, etc.