-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
There is a thread with a list of editors in the Miscellaneous forum, you could check it out for suggestions. I personally have been using Edit+ for years and am very happy with it. Brief feature list (that I personally use and like): - Syntax highlighting for several languages - Lightweight without a lot of useless features - Good UTF-8 support - FTP/SFTP built in - Hex editor built in - Brace matching - multi-document - Regex find/replace - Find in files (searches all files in a dir for a string/regex) - Split windows
-
You can use assumptions like that to some extent but that doesn't mean they are really accurate. Some examples: - I go to your your site and start reading an article. I need to go so I bookmark it and come back a few hours later. When I go back I just go straight to the article. Depending on how you do your tracking, either you'll show me as having spent hours on the site or just two sessions of an unknown duration (since the article would be the last page in both cases). - I tend to open a lot of links in new tabs, but will not read them right away. Sometimes I can have a page open in a tab for 30+ minutes before I actually get to reading it. Again depending on how you implement your tracking you'll either see me on that page for the full duration or it will timeout and you wont know. Either way is not really accurate as I likely only really spent a minute or two looking at the page, there rest of the time it was just open in the background waiting for me to get to it. Creating an analytics system with any kind of reasonable accuracy is actually a pretty complex task. That is why many places will pay a good sum of money for a pre-fab solutions such as google's analytics package.
-
See the manual page for details and examples. var_dump pro tip: if you come across a function you've never seen before and want details, just go to http://www.php.net/<function name here>, eg http://www.php.net/var_dump That will pull up the manual page for the function (if the function is part of PHP itself, and not something custom made).
-
No, do not do that. You want to use both nl2br and htmlentities for your preview area. htmlentities to prevent XSS and nl2br to insert a <br> tag and the end of each line so they are visible in the html. The nl2br should not be used when you output them to the <textarea> though, as the newlines will be properly rendered there without needing the br tags. Continue using htmlentities however even in the textarea output.
-
Different render engines may use different widths for what they consider a tab. This is why you can tab something out so it looks really nice in say notepad, then copy it into a web form or other editor and it will not line up quite right. You can use spaces instead of tabs to make sure things line up correctly as a space width is constant. You could also use HTML and throw the data into a <table> with some styling to make it real nice.
-
Neither, just: mysql < 4backup.sql The sql dump should include CREATE and USE statements for each db so it will restore all four as it runs.
-
Unless you plan on using the code in a CLI environment, you can assume $_SERVER['REMOTE_ADDR'] will be set and do not need to check it. If you want to be thorough though, never hurts to use isset().
-
You need to wrap your code in a big if statement to make it so that it will only run once the form has been submitted. Right now when you load the page it will attempt to insert your data, but there is nothing to insert since you have not yet submitted the data with the form. You also only need to call mysqli_connect once, your doing it twice right now (the second time incorrectly). You need to use the correct variable for the connection when using the other mysqli calls. <html> <body> <form action="insert.php" method="post"> name: <input type="text" name="name" /> email: <input type="text" name="email" /> password: <input type="text" name="password" /> <input type="submit" /> </form> </body> </html> <?php //Check that post data is received if (count($_POST) > 0){ $link = mysqli_connect('localhost','test',''); if (!$link) { die('Could not connect to MySQL: ' . mysqli_error($link)); } $sql="INSERT INTO emails (name,email, password) VALUES ('{$_POST['name']}','{$_POST['email']}','{$_POST['password']}')"; mysqli_query($link, $sql); mysqli_close($link); } ?>
-
If you want to display leading or tailing zeros (eg, 2.50 vs 2.5) then you have to cast the number to a string, apply the extra zeros, then output it. For displaying a number to a certain decimal point value, number_format will handle this easily. If you want leading zero's you'd use str_pad or sprintf.
-
You would format the numbers when you print them out so that they all have the same amount of digits after the decimal point. You can use number_format to do this.
-
The variables defined can vary based on the server and the request, but some are fairly standard and very likely to be defined (such as REMOTE_ADDR). Any index with the HTTP_* prefix may need to be checked as those are usually derived from headers which may or may not be present in the request. IIS used to not define DOCUMENT_ROOT, but newer versions do now. If you plan on ever using the script in a CLI environment as well, then you will want to check as a lot of them will not be defined there.
-
The property way to use a parameter as a reference is to declare that in the function, then just pass the variable as normal. Example: function myFunc(&$ref){ $ref = 567; } $v = 123; myFunc($v); You should only be using the reference if you need too. Your pasted code doesn't look like anything that would need to use a reference so just remove it.
-
I usually just start out all my ID's with INT UNSIGNED which allows up to 2 billion. Chances are no table in anything I do will ever hit that, but if by some miracle one did the type could just be upped to bigint without much trouble. I don't really know about how phpMyAdmin works, but for numeric types the length parameter does not affect how much space is used or how many digits you can store. It's used only for display purposes when you SELECT that number, and doesn't really do much unless you use the ZEROFILL option to pad zeros.
-
Maybe not on that page, but they did at somepoint, otherwise how would you know what to fill in? So long as your not setting it up so it will pre-fill based on an ID number in the URL or something like that, there is no problem from a data-leak point of view. The user should only be able to see whatever is on record for their account. The same way we've told you in the past, you run any user-inputted data through htmlentities() before you display it on the page. Your code shows you doing that so your fine.
-
What you log will depend on what the nature of the error is. For instance, for a DB error you would want to log the query text you are using and any variables your using as parameters for that query. Then you'll be able to re-assemble the query and see what went wrong. If you had an error say opening a file you'd want to log the name of the file being opened, what the error was (permission denied, non-existent, etc), and for good measure maybe the [m=getcwd]current working directory[/m] and [m=get_include_path]include_path setting[/m]. There could be various other types of errors you might have, each will have it's own data that needs logged. Since the information you need to log can vary from error to error you'll need to gather all that information at the time of the error and either pass it to your result script or log the error at that point and just have the result script display the message to the user.
-
You generally don't make a class which only has one function to process the data. In those cases you'd just use a regular function. Classes have several functions which all do various things to the data. You pass into the constructor any data that the whole class will need. Individual functions would be passed any extra data that they might need. Generally you avoid doing any significant amount of processing in the constructor because it makes it easier to extend a class if you do the processing in methods which can be called. You can't return anything from a constructor. The constructor is just for setting up the class by assigning properties or any initialization work. The "return value" is always the newly created object.
-
Aye, I did that too. Less for D3 though and more for the beta access heh. I'll check it out since I get it though. Maybe not launch day but at some point. Hakkar/Alliance for me. I don't play much these days though.
-
[m=pdostatement.fetchall]fetchAll[/m] returns a multi-dimension array with the first dimension being a list of rows and the second being the columns. You either need to adjust your code to take that into account (eg echo $logged[0]['username']) or change it to use [m=pdostatement.fetch]fetch[/m] which will only return one row. Also if your going to use PDO, you should take advantage of bound parameters: $ff = $dbh->prepare('SELECT * FROM db_members WHERE id = :id AND password = :pass '); $ff->execute(array(':id' => $_SESSION['id'], ':pass' => $_SESSION['password'])); $logged = $ff->fetch(); echo $logged['username'];
-
I'm sure this is the hangup in why they can't just use google's directions api w/o paying for it; From what I made out of their page on the maps api for business, it seemed like it came with access to the directions api, not that you'd have to pay more for that. I could be mistaken though. I don't know of any alternatives though for you, sorry.
-
how would i write, if $a has 1or more of $b do something ?
kicken replied to ricky spires's topic in PHP Coding Help
What are $a and $b for example? That will likely determine what function you'd use. -
I doubt one over the other would make any noticeable difference in speed. It's mainly a readability thing. You can certainly use in_array for just two values if you want. the three or more is just kind of my personal rule as I find that is when it makes the most difference readability wise (exact number varies some on the length of the values).
-
Nobody is going to wade through that much code hunting for some problem when you don't even tell us what the problem is. Are you getting an error message? If so what is it, exactly? Do you just get a blank page? You need to tell us what exactly is not working right, what it is doing, and what you expect it to be doing. You should also attempt to narrow down the problem area and just post the 10 or so lines around that area, not just dump the entire file.
-
Their precedence values. In your particular usage they both have the same end result. If you have a list of values to check against a variable using an OR condition, you can use in_array as a cleaner method of doing it. I find it doesn't really matter much until your at 3 or more values though. $values = array('/pmi.php', '/pmsent.php'); if (in_array($_SERVER['PHP_SELF'], $values)){ ... }
-
If your using strings for the keys and not numbers, which I assume you are since your using mysql_fetch_assoc, then array_merge should accomplish the same thing as array_replace. I assume you have more than just that one column to replace? If not you'd probably be ahead to just do $row2['l_desc']=$title2;