-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Where do you put opening curly braces when defining a method?
ginerjm replied to NotionCommotion's topic in PHP Coding Help
NigelRel3: It is only consistent with your other examples if THAT is the style you choose to use. -
Where do you put opening curly braces when defining a method?
ginerjm replied to NotionCommotion's topic in PHP Coding Help
Compared to the rest of my life, this style is about the tidiest thing I have ever done. -
Where do you put opening curly braces when defining a method?
ginerjm replied to NotionCommotion's topic in PHP Coding Help
Whenever I set up a pair of braces it is as you did in sample 2. Function headers, ifs, while, foreach, anything using {} will always go to the next line to begin. I also always indent one tab stop once the braces are setup. So my statement is at column one say and my braces will also be in column one, but starting on the next line. Then the statements inside the braces will be in the next tab stop. I find that this makes it much easier to recognize the code and to follow it when I'm breezing thru it looking for something. It also helps to see the flow since everything is not all in column one. This works well if your IDE automatically recognizes where the previous line is indented to and matches it when you hit the enter key for the next line of code. If it doesn't this style may be more of a pia than a help. -
Let's go back. "Trying to convert to a function". One could simply put a header on a block of code, wrap the code in braces and voila! You did it. But - a function is more than that. It is a simple set of code that does a certain "function" for you. You have something that works great and you need to use it in multiple places so you 'package' it and use it as an include module and simply call that function 'name' when you want that certain action to happen. Obviously you have to ensure that the contents of that function can stand on their own and not rely on multiple 'outside' processes, vars, values, etc. If it does, perhaps the function is not that isolated, meaning it does too much perhaps. When you get the code down to its bare minimum you will have code that relies on just a few (2-3?) variables that you then place into the function header and supply to the function when you call it. So hopefully what I've just described is the same thing you are trying to accomplish. The question now is: what about this is being so difficult? Show us something that you have created and tell us what it "isn't doing".
-
Uh, Which line is not working as it is supposed to? Your question is a bit unusual and nothing in your code is.
-
Warning: mysql... expects parameter 1 to be resource, boolean given
ginerjm replied to wintech's topic in PHP Coding Help
As Benanaman said and as you apparently agreed with Thinsoldier - using MySQL* functions is the wrong way to go. It is deprecated and has in fact been completely removed from PHP 7 (hence the different message I suppose) so why do you go ahead and provide the OP with even more outdated code? OP - as mentioned you should switch to using either mysqlI (note the I character) or PDO methods to access your database. If you are not doing your own hosting then check with your provider to see which interface they support and start using it. I and many others on this forum do recommend PDO as, after the initial (small) hurdle that anything new presents, PHP is pretty easy to use. That and the use of 'prepared queries' (look it up) will greatly modernize and protect your future coding endeavors. -
Its called a query string.
-
Multidimensional array print sertain values
ginerjm replied to Jsuperman2's topic in PHP Coding Help
A pretty complex structure. Can one even do this? Arrays usually have a series of pairs (key>value) not pairs pointing to more pairs. Of course I could be mis-reading this but it is confusing to look at. Is this Really your structure or just something you wrote here and don't really have? -
Some points to think about: - The $selector var will not be set if there is no GET parm. This generates a warning message. You should handle it more directly. - instead of the multiple ifs, look up the switch statement and use that. Don't forget the 'breaks'.
-
OMG! I was so wrapped up in the 'by reference' thing that I didn't see the obvious typo in front of me. Thanks for the quick response.
-
Thought I understood how this works but having a problem making it work. Here is my code: foreach($_SESSION['golf_entrants'] as &$row) { if ($row['id_code'] == $id) { $row['entry_name'] == $name; $updated = true; } } $row is a two element array that is created by a fetchall from a query that grabs them. If my argument ($id) matches the element for a given row I want to replace the row's name value with the new $name value. Nothing is being altered at all.
-
The reason for that error message? You can't issue a 'header()' command once you have already done ANY output to your client. Even an inadvertent space char at the beginning of a line of code outside of php mode would do it. Usually headers are issued only in php mode before you get to the point of issuing any html for that reason.
-
Uh.... Weird and Reason would be the words you were looking for. Happy you solved your problem, whatever it was and whatever you did.
-
how to make notification menu in my project to work
ginerjm replied to shan2batman's topic in PHP Coding Help
Do you know that the php code is actually running error-free? You don't seem to have php error checking turned on and you don't do any check on failures for anything you do. At the very least - put an alert in your jquery code when it is called to see that you are actually getting there. -
Also helps if you post the offending code for those of us who won't go clicking on outside links. The forum has code-posting tags to help highlight your code in your posts.
-
I don't know what actual mail command you are using or what mailing package, but usually the bcc: is setup in the header of the email being sent. Check out the simple PHP "mail()" function in the official php manual to see what the headers should have in them.
-
All that code posted but so little of it is actually PHP. Do you do tests on your connection results and db select results? You don't do it on your query results so there are several possibilities for failure right there. Also - echo out your query statement before executing it to be sure you have it setup correctly. A good design practice is to completely separate the bulk of your html code from the php code and perform the latter first. Build your dynamic content into php vars and place them within the static html and only THEN do your output. Makes for a more readable (and understandable) script which also becomes easier to modify and to maintain as time goes by. Comments help to.
-
THATS all you wanted? ROTL!
-
Puzzling. Someone has gone to a lot of trouble to build a certain structure and is apparently unwilling to change that process. Now you want to flatten that structure out and just create a set of variables out of it? What is the process that you are doing with the contents of this array and why can't it be done with the already-known and defined array structure names instead of a whole new set of variable names?
-
Sorry but you really need to learn how to stay either in php mode or out of php mode and stop switching back and forth. Your script is way too hard to follow.
-
Need some help - pick random lines from text files & email
ginerjm replied to StudioWorks's topic in PHP Coding Help
A better approach which would require more setup work would be to create a table that has an categ/file code to group the 10 lines from each of the 5 files and another "seq" number to identify each line in that categ/file code. Then you simply use the rand function to pick a number from 1 to n for each of your categs and perform a query that selects the categ/seq values that match the random ones selected. Then you do the email. Your current method involves having to open and read each file separately to get your data. Building the db would be much easier to work with and allows for very easy changes to the data to add or remove lines. Just my $.02 -
I liked Jacques answer better!
-
1 - I asked you to be sure that error checking was turned on. I don't see it mentioned at all. 2 - you post your second block of code called "index.php" but I don't see any php in it at all. ?? 3 - you are using the MySQL db interface. STOP. NO. WRONG. Check the php manual for the big red warning messages and then use the suggested alternatives. 4 - you do multiple php function calls to external resources (the database server) and don't check to see that they in fact worked. A good programmer always checks results of things like that to be sure his app doesn't break. Again - if you check the php manual you will see how the functions should be used and how to check their results. 5 - You really need to do some reading and learning about things. You wrote an html form without knowing anything about how the form and php are related. I will simply say that you need a name attribute and let you do some reading. It will be good for your development. 6 - you posted your code but have some serious errors. Look at your first if statement. And your second if statement seems to be missing some of your thoughts. PS - your stored password s/b already hashed. See my signature for how to use error checking. Check this link for the official PHP manual - especially the function reference here: http://www.php.net/manual/en/funcref.php
-
Work step by step. Make sure that your db connection is working properly. If not, post it HERE and not somewhere else so we can debug that with you. Then move to the next stage and post that HERE if you are having problems. Be sure php error checking is turned on as well. Many of us (I mostly!) do not click on embedded links here or anywhere when the forum provides the means for showing us the (necessary) code to be examined. Try and limit the amount you post to that portion that is where you think we need to look. Such as posting an entire html page when we probably only need to see the form part.
-
the server responded with a status of 406 (Not Acceptable)
ginerjm replied to oracle765's topic in PHP Coding Help
I second Barand's request - please wrap your posted code properly in code tags: php & /php themselves wrapped in [] Also - try turning on error reporting which you are currently turning OFF at the top. That may show you some problems. Perhaps you could add some comments to the different blocks of code to help (you and ) us to follow what this script is trying to do when need to re-post.