Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by gizmola

  1. In order to get help with a problem you need to provide more information than "nothing happens". If you don't learn to debug a basic problem like this, how do you expect to ever get anything working? So obvious questions? Did you check using a browser developer tool what is happening in the network console? Does your php contact script literally include this line? $to_email = "you@yourdomain.com"; //Recipient email, Replace with own email here
  2. When you are using PHP as part of a web server through cgi or an apache module, then the http server is handling HTTP (tcp wrapped) connections. This is obviously not what you want. The webserver is in the way, and it is also wired to communicate via HTTP, which is a request/response protocol that is not inherently persistent. So when you create a listening application you have to utilize command line php. Another popular alternative to writing our own socket server, would be to utilize a websocket server. There are some servers out there already, written in PHP. See: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=php+websockets+server&*
  3. Well it appears that whatever you cribbed this from is passing the client_id as a hidden form object. To get things from a POST-ed form, you would use the super global array $_POST. // Add to top $client_ID = $_POST['client_id'];
  4. Ok, but let's look at what you are actually after here. My best guess: foreach($selected_lender as $item) { echo"<br>"; echo $item['types'][6]; echo"<br>"; //echo $item } This is how you would reference an array element of a nested array without otherwise nesting another foreach loop.
  5. Ok, so first things first -- why? if(session_id() == '') { session_start(); } Do you want sessions or not? If so, you should just have session_start(). $_SESSION is a super global. In PHP superglobals are variables that are available everywhere and thus visible inside functions. So, in this case, your function has little to no value in terms of the passing of a parameter. Quite frankly, it would be really bad practice to do what you were trying to do even if it did work. One purpose of a functions is to hide details from the rest of the program, so setting/unsetting a variable inside a function that is otherwise global really goes against the idea of "information hiding".
  6. When you have the browser download a file, it is not going to treat it like a standard image. Any such handling would be left to the operating system.
  7. Please bind your parameters! See http://php.net/manual/en/mysqli-stmt.bind-param.php You need to do these queries one at a time. You can't just have a bunch of sql statements as one big string. That won't work. If this needs to be a single transaction then you need to: Have your tables be using a mysql engine that supports transactions. Usually people use InnoDB. Utilize the begin transaction and commit. See: http://php.net/manual/en/mysqli.begin-transaction.php
  8. I'm not clear on the criteria for emitting a new . With that said, if it's simply a fixed number of rows per table row, then you want to add a simple counter and then the modulus. For example: $i = 0; echo '<tr>'; while($row = mysqli_fetch_array($result)){ $i++; if ($i % 4 == 0) { // End/Start new Table Row echo '</tr>'; echo '<tr>'; } echo "<td><h1>" . $row['text'] . "</h1><img src=" . $row['link'] . "></td>" } // Close final TR echo '</tr>';
  9. Unless you are writing portable code that runs on pseudo databases for some reason, there isn't much of a concern. Don't misinterpret that warning. If you are writing specifically to mysql, it is going to work fine. For select statements you can always do this, although it's lots of extra overhead: SELECT count(*) as countof FROM ... WHERE etc. This query will always return a result that contains your number of rows to be returned in the next query, even if that number is zero. Of course you have to author these queries for every SELECT statement which few people want to do, but it's an alternative to doing the query and relying on the client result set feature that provides num_rows, or using Mac's idea. In cases of large datasets that need to be paginated, Mac's work around would be bad.
  10. You either have a list or you don't. If you don't have an email list there is nothing to unsubscribe from.
  11. Spousename, SpouseAddress, etc, are arrays because this is an application for Mormons? I joke, but in order to understand how many times you need to loop, as well as reference the array elements, I would need to better understand what the data would look like in the case there are multiple entries. I don't see the correlation between the possible arrays that leads to individual rows of data where some of the data is the same, and other data would vary. Probably in this circumstance you would want to write a function that builds a $rowData[] array where you have everything you need to do your inserts and then you would for loop through that array doing a prepare/execute for each array element. Just strictly answering your question, is basically me showing how you reference data in a numerically indexed array. One way is to use a for .. loop, another is a foreach. I really can't figure out from your code or your description which is appropriate. With that said, simplistically: if (is_array($_POST['sourcename'])) { $count = count($_POST['sourcename']); for ($x = 0; $x echo "{$_POST['sourcename']} "; } } As you will see from that (or from var_dump() of the various POST arrays, you will have a simple array of strings, that can be addressed numerically starting at zero. echo $_POST['sourcename'][0]; // first element echo $_POST['sourcename'][1]; // 2nd element etc. As I stated, the problem is that some of the fields could have 3 elements, while others have 5, or 1. Your database structure seems to be flat, but it's also unclear how the data is related on a row by row basis.
  12. The site itself is owned by a server hosting company named Infinitum Technology, who operates their hosting business as http://www.rapidvps.com/. They purchased the site from the originator a few years ago. RapidVPS provides the server and bandwidth for the site, and also receives any advertising related income it might be earning. The content of the site has always been administered, moderated and otherwise provided for free by volunteers. Many of those volunteers will accept a donation, but if not, don't worry about it. We rarely receive thanks, so it's always nice to know that people are being helped here, as this is the primary reason that most of the people who answer questions do so altruistically and with the desire to give something back to the PHP developer community, not to mention the primarily volunteer PHP project participants. We want PHP to continue to thrive and grow, and for many of us phpfreaks is our way of contributing to that effort.
  13. Yes well when you define an html form element as an array, it can have multiple values and will be an array when converted to an internal PHP variable. For example, you have: It's not really clear why you have some fields defined as arrays and others that are not. I can't comment on that, but it's fishy. In order to figure out what you have there are things like is_array() in php. if (is_array($_POST["sourcename"])) { } It seems to me if this is a multiple line item type application, then it ought to be all or none for the fields in the POST. Once you've detected that those are arrays rather than simple strings, you will need to loop on the section of code that binds and then executes the queries. With mysqli_ you don't have to prepare the query again, but only bind the values and then execute the query.
  14. The main problem you have is that you are starting a new list for every row, rather than only when the outer category changes. This type of code is tricky when you have to wrap things inside tags without knowing for sure what the complete data set is. My advice to you would be to build an array which matches the exact structure and hierarchy. In order to do this you will need to read all the data from the query in first. Use a nested array to accomplish the structure. So code like this will work: $categories = array(); while($row = mysqli_fetch_array($result)) { if (!array_key_exists($row['nume_domeniu']) { $categories[$row['nume_domeniu']] = array(); } $categories[$row['nume_domeniu']][] = $row['nume_subdomeniu']; } var_dump($categories); This should give you an array that fits your desired menu hierarchy. All that is left is to create a routine that will foreach through the structure outputting the outer and inner UL's, and required LI's.
  15. Please keep in mind that english is not his primary language either, so what you interpret as a terse dismissive response, is most likely not meant to convey dismissal but rather just be matter of fact. Having 2 tables is a bit wonky, but I've seen it done in many places. Small dataset and a join, but then anything static like a menu benefits greatly from caching. It's not egregiously incorrect as in having repeating groups etc. so I tend to try and work with people rather than demand they conform to my design, unless it is so hopelessly wrongheaded I don't see the point in continuing. In those cases, I think it's best to just make your point, and if you feel your good advice is being ignored, just move on to the next thread.
  16. The best framework is the one you are most productive with. Of the 2 you listed, they are both of a type, and that type is that they were designed around "convention". What that means is that they utilize conventions to provide you a lot of "magic" and many people enjoy the productivity that comes along with magic behavior. They also interface with databases via an implementation of the ActiveRecord design pattern. If you need a database you are going to use their db layer, and the pattern is Active Record. It is fast and easy, but limiting and kludgy in more advanced applications in my experience and does some binding of business logic and persistence to the database model code which at first glance is often appealing to people but has inherent issues. Just for reference, Laravel's database library is called Eloquent. You will get farther in your research knowing that when googling. Cakephp is very simple, and also very old. It's simplicity is appealing to many developers who are starting out, but it's really dated. If I needed to choose between those 2, I would choose the more modern of the two, so I'd choose Laravel. As an alternative, there are frameworks that are designed around configuration rather than convention. There is less or even no magic, and there are those who do not want magic behavior baked into their framework. Symfony is the big competitor to Laravel these days, and that is the real choice most people are making (symfony or laravel). Symfony can be used with various database layers but it has good support for and cross pollination with the Doctrine2 project, which is an alternative to an ActiveRecord based ORM. Doctrine2 implements the "Data mapper" pattern and I prefer that to Active Record for many reasons. Here is a really nice introduction to this subject: http://culttt.com/2014/07/07/doctrine-2-different-eloquent/ I also have to add that there are many "micro framework" choices out there like slim, lumen and silex. You have a lot of high quality choices and the state of php frameworks is better than it has ever been, given the move to component library development, namespaces, PSR-0 and the creation of composer.
  17. Yes. Just stick it in the same place you had the other script(s). I thought you were already adding/changing scripts, so I didn't think it would be a problem for you. Call it anything you like -- phpinf.php for example.
  18. Phpmyadmin is a set of php scripts that allow you to work with mysql. It's not really what we're after, although I did see some things that answer a few questions for me. With that said, make a simple php script with this in it and access it: phpinfo();
  19. This seemingly simple question actually calls into question a number of things you are doing that aren't great from a security or SEO standpoint. While Jacques1 handed you a technique to identify the currently requested parent script in a web server environment, your code reveals some things you are doing that could be better handled explicit with a better architecture pattern. There are many out there, but the most typically use are front-controller/mvc. For example, if you had a front controller script, you would already know where you were in the control structure all the time, and that state could be passed into the menu. In most apps these days, people are moving to a richer client experience with more javascript client code/ ajax etc., and less dependency on page requests. It is also much better to obfuscate your underlying architecture for SEO purposes, not to mention the fact it lessens what others know about your hosting environment. Google likes this: yoursite.com/fly-control Much better than yoursite.com/fly-control.php Your site is easier to maintain as well if you are using a front controller that all requests are going through. With the proliferation of small easy to use micro frameworks like slim, silex, lumen etc. or even symfony3 configured as a microkernel, the answer to your question could be very different if you improved your underlying site architecture. For reference: http://symfony.com/blog/new-in-symfony-2-8-symfony-as-a-microframework
  20. Hi ClipboardCode, First off I understand that your feelings have gotten hurt. You came here with an app you are proud of, and want to share with people, and you thought was already pretty good, and instead you got crapped on, or at least that is your perception. I hope you can at least try and understand that the people responding to you are hard core best practice professional php/web developers with years of experience, and a highly opinionated stance on best practices and a low tolerance for security issues. It also seems that you didn't get to some of the questions you felt you had, which is a shame. But the obvious things to me, that would ultimately be of value to you is in the developing of an understanding of the state of the art in terms of professional php development, as well as the modern state of open sourcing and sharing a project with the world. That would include things like: Use of Git/Github or Bitbucket for your project code, since you intend to share it freely. Obviously github is ideal for this. Use of php component libraries where appropriate Good clean code with MVC, separation of logic & presentation Best practices for security, and a security audit Open source licensing Let's just say your code gets out into the world, and it has huge security holes, which clearly it does. Would you want your reputation and the reputation of your company to be attached to that from here on out? While I come to this late, and have never seen the code in question, the people who did, and who replied to you, have expressed that concern. It seems like what people have been saying to you is that you could use a ground up rewrite, and that is certainly a bitter pill to swallow, but that effort could be enormously valuable to you as a learning experience. It might not have been what you originally were looking for, but the potential for that still exists for you, if you so desire. In the meantime, I highly recommend that you familiarize yourself with the symfony components, use of composer, and perhaps even read a little about dependency injection. I have recommended this video to many people as a way of starting to understand how modern php development had evolved into something competitive with other language ecosystems and the reasons that needed to happen before php became obsolete. This is almost 5 years old now, so lots of improvements in php and the component ecosystem, but it's still a great introduction: "Wonderful world of Symfony components" A php centric introduction to Dependency Injection: http://fabien.potencier.org/what-is-dependency-injection.html
  21. Serverman, The purpose of threads is to have a topic per question. This seems to be turning into a personal topic for you, so I'm going to close it now. Please create a new Topic for your current question, titled as best you can. Something like "Calculate rent payment schedule" or whatever is appropriate. You can link back to this thread in your post, and those that want to check out the backstory can.
  22. I see nothing wrong with the query that would explain this. There is a concern that date is a keyword in many databases. However if the query worked originally it should still work with the column wildcard. With that said, you didn't tell us what database you are using, nor did you provide any other code. For example, the query might actually be working, but your code extracting the data from the result set might have an issue. If it's mysql you could try for a quick fix by using backtics around the date keyword like so: SELECT * FROM NBA2017 WHERE player='$player' ORDER BY `date` DESC LIMIT 10";
  23. An undefined index occurs when you try and reference a key in an array that doesn't exist. Based on the info you provide that was the attempted referencing of "$_POST['company_address']". Clearly, prior to the api actually returning something, that variable didn't exist in the POST data. You can improve your error checking by using functions like array_key_exists or trying: if (isset($POST['some_key'])) { } else { // Deal with error, it's not going to work }
  24. What server OS is your php script running under? Seems like PDO may not be installed/configured? See http://php.net/manual/en/pdo.installation.php
  25. This depends on your database schema. Often with mysql people will utilize AUTO_INCREMENT which uses mysql built in sequence generation. When you do the INSERT, you should not specify the ID column in the INSERT. Mysql will fill it with a valid sequence number when the insert occurs. You can then use a routine in the mysql api to get the newly allocated ID if you need it. mysqli_query($db, "INSERT INTO songs (songName) VALUES ('{$_GET['songname']}')"); You might want to note how I interpolated the array variable in a cleaner way using {} to surround it rather than all that concatenation which is hard to read, not to mention error prone.
  • 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.