-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
If you are positive that it is always a 4 byte length field, you could use substr() on the string.
-
How can I display the name of the month that the user requests?
ginerjm replied to jaytea41's topic in PHP Coding Help
Read up on the date functions. There's tons of them in php. http://www.php.net/manual/en/funcref.php -
You reference the index 'company_address' in two places. One as an element of $_POST and once as an element of what I assume is a query result. So - where does this ACTUALLY get defined? And which line is the problem? Do you have a query that looks for 'company_address'?
-
PHP Data Grab Project - Need help with security
ginerjm replied to ClipboardCode's topic in PHP Coding Help
And don't use the @ operator. Why in h... would you? -
Doh! Thank you for that slap upside my head.
-
Help an ignorant soul to visualize this construct. would it look like an array of the 5 indexed elements themselves under an index of $overall? Or would $overall be an element under each of the 5 elements? Or something else?
-
When I test this line: $overall = 0; $pt_overall = array('A' => 5, 'B' => 4, 'C' => 3, 'D' => 2, 'E' => 1)[$overall]; I get 'undefined index 0.....' message. IF you did assign this construct to a var, can you show me what that var would look like? This whole thing is so foreign to me I am surprised PHP even tries to interpret it.
-
I don't recognize this at all. You say "an assoc array indexed by $overall. Isn't the assoc array already indexed by 'A', 'B', 'C', 'D' & 'E'?
-
What are you trying to ask? What kind of structure are you trying to create?
-
One doesn't learn how to program without actually programming. This forum is here to help you learn, not to write it for you. What Barand took the time to explain to you is one of the first steps to learning programming and creating algorithms. Adding code to that understanding is the second step. Take some time to educate yourself and then have some fun writing some code and then show us what you have difficulty with.
-
How to get values of dynamically generated text area inputs with php
ginerjm replied to Banky's topic in PHP Coding Help
The point I was making is there is a learning process that involves some reading and some education before you jump into coding up apps like you are doing. And if someone fed you this crappy db design to work with obviously they also need to do some of that reading. Programming and writing viable apps is not simply copying some stranger's code and sticking into your concept of a solution. It is work, just like learning auto repair or house painting or even gardening. My response to you was so negative because it was so far off-base already. It wasn't personal. -
I think you need to explain yourself further. Or use better language to describe it. You have a "page" that runs for 24 hours? What do you define a "page" as? I define it as the image that the client is showing to the user. It can sit there doing nothing for 24 hours or more, but it is no running unless you have some JS code executing on an interval basis, certainly not on a constant one. You want the server to visit "the page URL"? Not at all sure what that means. Isn't the page url the thing that presented that "page" to the user/client, ie, a script? Although if you want the server to do something related to something on this "page", then I can see how it could be a completely separate cron task. This sounds like what Kicken is telling you to implement. Think about what he said again. If your "page URL" posted a time value to a table, your cron job could execute every 1 minute or every 5 minutes and look at this table for any records having a time value that has expired and do your bidding. And if anyone does stumble upon your waiting "page" that could also trigger a record in the table telling your cron job something else.
-
When should PDO::closeCursor() be used?
ginerjm replied to NotionCommotion's topic in PHP Coding Help
Point. Resources are cleared not on a function basis, but whenever they go out of scope as was explicitly said above. The same holds true for global values when the containing script itself ends. I too have rarely used close_cursor. In fact the 2-3 times I have used it I had to read up on it. I have only used it when I have multiple queries going on and want to dispose of the prior one. Also a rarity. -
Why do you need a cron job for this task? Normally a cron job is created to perform a task on a regular basis, not on a signal from a periodic script execution. Perhaps you need to re-think what you need to do. It's all very confusing to me right now.
-
Should I save all user inputs into 1 table or separate?
ginerjm replied to DeX's topic in PHP Coding Help
You should start with an analysis of what you are trying to store and evaluate what your tables need to look like. Obviously you need to define a key field (or two?) that will help you identify the sets of data you will build. Then you need to clearly define what each field(column) of data is to represent and how it is to be stored and how large it may be. Give each of the fields meaningful (but reasonable short) names. When you find yourself with multiple values for a single field (b) you will need to break this one out to a separate table, using the same key info to mark those records as you do in the first table. If you find that you have multiple "sets" of the same data then you can save them as separate records in the primary table instead © using a key value that helps to make these records unique if you need to locate specific sets of data later on. You should never join differing values of the same data into one field/column using a separator character to later break them apart. Never. This is when you do what I mentioned earlier as (b). Once you design your database it will be much easier to write the input forms and scripts to handle them. -
Eliminate that portion of the where clause with a variable
-
How to get values of dynamically generated text area inputs with php
ginerjm replied to Banky's topic in PHP Coding Help
I won't help someone who has such a woefully incorrect db structure. One should NEVER store data in comma-separated lists in a table column. Never. Not Ever. Break the data out into distinct columns if the pieces are truly "different" bits of data. If they are the same, then they should be placed into a single column (ie, multiple rows) of a secondary table that is linked to the first by a common key or foreign key value. You should do some reading on a normalized database. Good luck. PS - When you next post code here, please use the appropriate code tags such as php and \php wrapped in square brackets. -
Well said! I appreciate your honest response to the things I wrote about. Be happy to review and advise on your next post - especially if you do the things I suggested. See my signature for the error checking code you need to add. And - you should actually try to learn from doing your own research instead of just copying other's (feeble) attempts. You will have a much faster education.
-
Why not try to send a plain text email until you learn to do the right research to send an html-based one? Also - add error checking at the top of your script to point out php problems as they occur. And - don't bury a function into the middle of your code. It interrupts the flow of reading the code for no reason. Question - what is died() even used for? Question 2 - what is $email_exp for? Question 3 - if you are going to use html, where is the <body> tag?
-
You simply create an email - plain text is good - that contains the output of what you are trying to do in your script. Show variables as the script works along to ensure that it is doing what you expect. I then send the email to myself at the end. You can also use your address to send the 'real' output to yourself to ensure that it is sending the correct output. You can also avoid all of this simply by writing an ordinary script that outputs to the client until you get it right. Then you comment our the debugging echo statements and enable the email activity. Use a switch to control the debugging and another switch to control the actual email outputs. Ex. if ($debug) echo (something to help debug) .. .. .. if ($debug echo (something more to help debug) .. .. .. if ($send_emails) (call a function to send the production emails)
-
When are semicolons required after curly brackets?
ginerjm replied to NotionCommotion's topic in PHP Coding Help
Mac_gyver says not to use them after a brace, which is a true statement. The brace is not a php instruction line. It is simply a wrapper, like a paren. Benanamen says to use and not use depending upon the situation. Wouldn't you really rather just develop a good habit and use them where required and not have to think about it? Basically you put one at the end of every statement except the IF statement. Of course there is probably some syntax/statement that I never use which will probably be pointed out in a few minutes. -
When are semicolons required after curly brackets?
ginerjm replied to NotionCommotion's topic in PHP Coding Help
The question is really a no-brainer. Just use the semi in all appropriate places. Don't bother trying to outthink the compiler as to when you can "get away" with not using it. It will only come around to bite you in the rear. Consider this: You get used to leaving the semi off the last line of a brace-enclosed block of code. Then you add a new line to the end of that block and - voila! - you have a compiler error. So now you go back and correct it and wonder why you left such a simple thing off that line just to save a keystroke, only to lose time later on. As Benanamen said above - php wants one at the end of each instruction. Why debate it? -
And how does your algorithm handle web pages that use a reversed arrangement of quotes? ie, href='domain.com/page.php' Do you call the function twice?
-
How to add role in this code using if statement ?
ginerjm replied to AdeelZaighum's topic in PHP Coding Help
Mac-giver makes a good point about when to check for the 'current' role status. My method would force a user to re-login as he said. So - perhaps your 'security' function not only checks for a simple logged-in token, but then can also make a quick query for the role if the token is found to exist. -
How to add role in this code using if statement ?
ginerjm replied to AdeelZaighum's topic in PHP Coding Help
I see two problems. 1 - you apparently are storing your passwords in plain text. Do Not Do That. Do some reading on the concept of hashing your password in the database and then do the same thing with the user's input before querying it. 2nd - what do you want to do? You want to add a role. Fine. But in what context? The only thing I can guess here is that you want to control who can access what pages in your site. Therefore when you check for a proper login, grab the role indicator from your table along with the username and save that as a session var also. Now for each page that requires a logged in user you will need to check for the username begin set and if there is a required role for that page, check the saved role value. Personally I would write a function for this code that returns a Boolean so that you can later modify/improve this code.