Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. Not really the point. Just changing everything from mysql_ to mysqli_ does not address the problem adequately. You actually have to learn the new api.As for the code, try this and tell us what you get: while($img2 = mysql_fetch_assoc($resultimg2)){ var_dump($img2); die(); // $hours = $img2['serv_dur4.t1m3']; echo "<tr><td><td>" . $img2['serv_dur4.t1m3'] . ""; } This was suggested earlier --- you need to understand what the $img2 variable actually contains at this point.
  2. The point about restarting apache addresses your question from before. Yeah you have to restart apache anytime you change something while trying to debug this. A symlink is a file, as is everything in the unix filesystem. Of course some files can be directories. What is special about a symbolic link is that it points to something else, so yes you are right. However, what I was telling you is that if i have a directory like this: [david@penny apple]$ ls -lath total 8.0K drwxrwxr-x 2 david david 4.0K May 6 12:40 . --w--w---- 1 david david 0 May 6 12:40 macintosh.txt drwxrwxr-x 3 david david 4.0K May 6 12:39 .. [david@penny apple]$ cat macintosh.txt cat: macintosh.txt: Permission denied As you can see, I have a directory with one file in it that only has write permissions for user/group. I try and read that file using cat, it doesn't allow it. Now I make a symlink to that file: [david@penny apple]$ ln -s macintosh.txt symlink_to_mac.txt [david@penny apple]$ ls -lath total 8.0K drwxrwxr-x 2 david david 4.0K May 6 12:42 . lrwxrwxrwx 1 david david 13 May 6 12:42 symlink_to_mac.txt -> macintosh.txt --w--w---- 1 david david 0 May 6 12:40 macintosh.txt drwxrwxr-x 3 david david 4.0K May 6 12:39 .. [david@penny apple]$ cat symlink_to_mac.txt cat: symlink_to_mac.txt: Permission denied When I make a symlink it shows as having full 777 access, but the underlying file is still not accessible, because the permissions on that file are not ones that allow me to access the file. You can not change the perms on a symlink as they are basically irrelevant. As you stated, they point to the underlying file or directory, and those permissions are important. The user apache is running as, also needs to be able to access the directory and its files if apache is going to read them.
  3. As Psycho pointed out, your current code is trying to work with an associative array. No problem with that, just change mysql_fetch_row to mysql_fetch_assoc. Of course it just has to be said, that using the mysql_ api is deprecated and has been removed from php entirely. It is only a matter of time before you upgrade php and your code no longer works. You should be using mysqli_ or PDO/mysql. I'd recommend PDO.
  4. Take php out of the equation. Does your query work from command line mysql or phpMyAdmin or whatever tool you have that lets you issue raw sql to the database?
  5. Do you understand how symlinks work? It doesn't matter what the symlink permissions are, if the underlying directory permissions won't allow access. Also if apache doesn't allow access to the files or directory, you're going to get these permissions errors. It's an apache config problem. Also fwiw, with mod_apache... yes you have to restart apache anytime you change an apache configuration item or a php configuration item.
  6. We gave you specific fixes to get your code running. Make those changes to the best of your ability and post the results. If you make the effort people here tend to continue to support you. If not, they probably won't.
  7. phpfreaks is for php programmers, whether they be pros, hobbyists, students or hackers. What it isn't, is a cooperative of people sitting around waiting to do free work for people, although that certainly has happened inadvertently over the years. Absolutely nobody who answers questions gets paid to do so, in case that helps clarify things for you. It's not our way to tell people to GTFO, but I also don't think it serves anyone to think that we are sitting around here waiting to do free programming for people. PHP is extremely accessible in its simplest form, as in the case of the script you started with, and often people who aren't "programmers" are still smart enough to understand the basics and make simple changes. We are for the most part happy to help those people, so long as we perceive that they are making a genuine effort to learn enough to do the work themselves, rather than demand spoon feeding, ie. "please just show me the codez I need to make this work the way I asked you to". I might walk into Home Depot and ask them for help on what I need to do to put in a new bathtub in my house, even though I'm not a carpenter or a plumber. The Home Depot people will probably put up with a lot of stupid questions, but what they won't put up with is me demanding they get in my car, and drive with me over to my house, so that they can do the installation for me, for free.
  8. I think you have gotten a lot of good advice already. I just wanted to throw in a point about the state of php and architecture. PHP is now at a point where the state of the art is that people are building component libraries that can be mixed an matched in any project easily, with the use of the composer tool. The individual components are of higher quality especially when these components are backed by a high degree of unit test code coverage. It sounds like you are in the process of taking your old world library and approaching a substantial rewrite only to come up with a monolithic customized framework that will be obsolete and out of step with the state of the art in the php world, the day you get it running. If you were to break what you had down into logical components, what would you actually have? Where is the value in your code, and are you sure that there aren't many better components in existence that do everything your code does, only in a far more resilient and unit tested manner? For example, I would highly recommend you take some time looking at this page: http://symfony.com/components Dig into some of these components and compare them to the code you already have. How much overlap is there? Where are the things unique to your CMS you can isolate? If you can turn those elements into unique components, while at the same time replacing the ones you have that were probably done better in the symfony components, then you could approach this exercise entirely differently, and put together a component based version of your cms that leverages untold person - years of quality tested code. That's a very important gut check for you to do right now, in my opinion. This is the type of thinking the Drupal community did a few years back, and the phpbb people and the guy who created the Laravel framework. Component based projects are the present and future of php, especially for projects like yours. If what you find is that you basically need a framework that already handles 90% of things, you might find you're better off just using symfony2 full stack framework with the Doctrine2 ORM and moving all your database design into that, and isolating the specifics of your db designs into the ORM classes.
  9. Erik, Don't worry about pconnect. It was an optimization technique that in general caused more problems than it prevented. It's part of a large area of knowledge having to do with the different ways that php can work with a web server, and the way different relational databases work. Essentially pconnect was designed to create a pool of persistent mysql connections. When a php script runs, all the memory is instantiated at script start, and discarded at script end -- including all mysql connections. For this reason, there's no need to actually close mysql connections in scripts, because they are going to be closed anyways when the script finishes. However, in an apache/mod_php environment, php is actually part of the apache web server. Depending on how apache is configured, there is memory allocated for php scripts that gets reused a number of times. Since this memory is not discarded, scripts tend to run faster because the entire php environment does not have to be started for each request --- it's just reusing memory that was already allocated for a prior request. In some complicated environments, the mysql server that php needs to talk to is running on a different server, and the network overhead and latency involved becomes a bottleneck. Also with some databases (oracle for example) starting up a connection to the database from a client takes a long time. In the case of mysql, rarely are people in an environment where mysql is not running on the same machine over localhost. Secondly the mysql connection process is very lightweight and fast unlike oracle. mysql_pconnect is a bit of a hack for reusing mysql connections in the apache/mod_php environment, for edge case setups, in environments where they expect sysops who understand all this stuff and can modify settings and performance tune settings to make sure that the problems that can be caused by persistent connection pooling don't creep into your environment. There are any number of issues that can occur over time, when using _pconnect, and the problem is that these issues only emerge under load. I won't go into them, other than to say that using _pconnect in a standard one server LAMP environment is completely unwarranted at best. Fortunately, you are already well into your exercise of converting to PDO/MySQL and there's no need to concern yourself with persistent connections at all now, however, if you're just the curious type, you can read some more about what problems they were hoping to address in the php manual: http://www.php.net/manual/en/features.persistent-connections.php
  10. Oh yeah what ginerjm ^^^^^^ stated as well, which I neglected to state. Set a variable value: $foo = 3; Logically test for equivalence: if ($foo == 3) Oldest mistake in the book: if ($foo = 3) // well $foo sure does == 3 now!, and that's going to be true as well! All I can say is that all these mistakes have been made by lots of other people before you, so don't feel bad.
  11. Hi fatboymills, I will apologize in advance, because I know this is going to come off as a lecture, but sometimes you just have to be completely honest if you want to actually get anywhere. To use an analogy, you are approaching this like someone who found an iPhone, and you come into an electronics forum and ask people for "help" with replacing the built-in camera circuitry and camera lense so that you can take 2 pictures at the same time. It's an electronic engineering forum after all, full of people who design and engineer phones, so these people start to brainstorm, and only then do you admit that you have absolutely no clue about how the phone works, how the firmware works, how electronics work, and at that point, after people have wasted their valuable time getting nowhere with you because you are completely out of your element and incapable of actually engaging with them, your question is: "Should I go get another phone?" That's not the point. You have no business engaging with people on how to change a phone until you learn some basics about how the phone actually works, and how you can safely modify it. Your problem is trivial to the people who have already replied to you. You just don't understand the first thing about php. You need to remedy that if you want to achieve your stated goals. Sorry but it had to be said.
  12. Do you have Options +FollowSymLinks Enabled in your apache config or htaccess in some appropriate place? Symlinks won't work in apache with that at very least. If you're running mod_php, php has to play by the rules of apache.
  13. Let's try some proper indentation and see what we have: <!DOCTYPE html> <html> <head> <title>Your own do-while</title> <link type='text/css' rel='stylesheet' href='style.css'/> </head> <body> <?php $rollcount = 0; do { $roll = rand(1,6); $rollcount++; if($roll = 1) { echo " <div class=\"dice\">1</div>"; } if($roll = 2); { echo "<div class=\"dice\">2</div>"; } if($roll = 3); { echo "<div class=\"dice\">3</div>"; } if($roll = 4); { echo "<div class=\"dice\">4</div>"; } if($roll = 5); { echo "<div class=\"dice\">5</div>"; } if($roll = 6); { echo "<div class=\"dice\">6</div>"; } if ($roll = 3);{ echo "<p>There {$verb} {$rollcount} {$last}!</p>"; end($roll) } } } while($roll); { $verb = "were"; $last = "rolls"; if ($rollcount = 1); { $verb = "was"; $last = "roll"; } } ?> </body> </html> Hopefully you should see that you have blocks ended improperly, loops with statement end characters (the ";") and a function call (end) without a statement separator, that is also not appropriate whatsoever, as it as it works on arrays, which you aren't using. In short, right now the code you provided has syntax errors, so it's not actually running, nor will it until you fix those errors. Specifically let's start with: if($roll = 2); { echo "<div class=\"dice\">2</div>"; } Do you see the problem? How about this: if ($roll = 3);{ echo "<p>There {$verb} {$rollcount} {$last}!</p>"; end($roll) } } Same problem, but also you have a random end-block "}") in there. And to make matters worse, you are trying to create a string with variables that are not initialized and have no value yet, as they don't appear in your code until after the do-while loop has finished. First thing to do is clean up your code so it's actually syntactically correct. It's really important to have an editor that helps you with proper indentation of blocks, or this type of mistake will creep into your code. Just to throw in my 2 cents, but if this assignment doesn't prohibit it, your code would be much cleaner with a switch statement instead of the repetetive set of mutually exclusive if $roll = ... blocks.
  14. 1. A foreign key is a column in a table that is NOT part or whole of the primary key of that table, but instead is the primary key of ANOTHER table. This is why it is called a "foreign" key. It's not *my* key --- it's that foreign tables' key. Logically, you have accomplished this by creating the address_id column in client, that will let you relate a single foreign address row to a client. Just make sure that the datatype of the address_id column in client is exactly the same datatype as it is in Address. (Signed vs Unsigned, int vs bigint) 2. Automatic behavior associated with foreign keys is accomplished with constraints. With mysql you need to use a storage engine that supports foreign key constraints. This means using the InnoDB engine for your tables. 3. The constraint is responsible for enforcing/constraining the relationship between the tables. If you are using the MyISAM engine for your tables, you can still relate clients and addresses and get the benefit of a proper relational design. In this case, the implied benefit is that many clients will share the same address. If that is the case, you require less storage. 4. Assuming you are using Innodb, this page in the mysql manual covers the syntax for creating constraints: http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html In your case, if you've already created these tables, then you want to alter the client table, using the syntax in the manual page. Something like this is probably what you want: ALTER TABLE CLIENTS ADD CONSTRAINT FK_Address FOREIGN KEY (address_id) REFERENCES ADDRESS(address_id) 5. In this case, you really don't want anything to happen automatically when you delete or change an address row, other than to prevent a client having an address_id that does not exist in the address table, or to prevent the deletion of an address that is related to an existing client. So you won't want to specify any CASCADE clauses for this relationship. 6. As long as the address_id column in CLIENT isn't set to NOT NULL, you will be able to utilize the "0 or 1 to many relationship", allowing you to create a client row that does not have an associated address. 7. There is no magic statement that will set the address_id in the client table. You need to set the value of address_id in your INSERT or UPDATE statements that involve clients.
  15. You might have more luck pinpointing specific classes/functions etc. that you think might have an issue or could be improved. Speaking generally, it would be easier to maintain if you put the presentation code into "template" files that you include, or use a template engine for. I'm not going to suggest any of the sophisticated compilation template engines like smarty or twig, due to the fact that you are integrating with bulletin, but take a look at these: Blog post that shows a simple effective way could pull this off: http://chadminick.com/articles/simple-php-template-engine.html Some simple template classes that can be used with a simple include of their template class: http://phpsavant.com/docs/ http://www.tinybutstrong.com http://www.raintpl.com http://gabordemooij.com/se/ You might also look at breaking up a lot of the logic sections into functions, named appropriately to represent the specific purpose they fulfill. That way if you decide to move things around or add or remove sections, it will be much easier for someone to understand the code and make changes.
  16. Hi PHannum, In the future, just use the code bbtag around your code blocks. Easier for everyone. Hopefully between bsmither and jacques1, you can see that you need three params to your self::put() method call and you have only supplied 2, it appears by accident.
  17. The only type of index that will allow for finding a sub string inside a string with any sort of efficiency, is a full text index. There are also specialized search engines you can use (and most frequently these are what is used to provide searching against a number of facets) -- like sphinx, elastic search or solr. You can apply mysql full text indexes, but there are caveats and a lot of things you have to learn about in order to use them, although the learning curve and deployment issues involved with full text engines are similar. I would suggest you do a bit of research, and certainly you can experiment with adding some mysql full text indexes. If you do go that route, make sure you drop any of the other indexes you've created specifically to speed your search.
  18. As long as you are searching for 'Brisbane....' then LIKE '$var%' will use indexes where they exist.
  19. Just to elaborate on what Barand was saying, whenever you use a LIKE query with a wildcard IN FRONT of the search criteria: LIKE '%$var%' Then an index can not be used. The entire table has to be scanned. Since you have this: (apl.Location LIKE '%$q%' OR apl.City LIKE '%$q%' OR cl.CountryName LIKE '%$q%' OR prl.RegionName LIKE '%$q%') GROUP BY apl.Loca Well you are table scanning the location, city, country and region tables at very least. A query that ends with a wild card however, will use an index: LIKE '$var%' And of course an exact match is best.
  20. To make it database driven you simply need to create a banner table. You'll want to have a structure like this: id int (primary key) url varchar(512) image varchar(128) active tinyint As for rotation, so long as your banner ad table doesn't get larger than a thousand rows, there isn't much of a concern, however, I would highly recommend reading this blog post: http://jan.kneschke.de/projects/mysql/order-by-rand/ With that said, the simplest solution for you, that will certainly work fine for quite a while: SELECT * FROM banner WHERE active = 1 ORDER BY RAND() LIMIT 1 If you expect rotation over time without reloads, then cyberRobot's point should be taken into account. Often people will utilize an iframe and place the banner in the iframe, which can then have a simple meta refresh tag in the header of the code. Ajax polling offers a more sophisticated option to cyberRobot's point, or you could alternatively fetch a number of ads initially and use a javascript timer to rotate them.
  21. I agree strongly with everything Jacques1 wrote. In regards to prepared statements on insert, IF you have multiple inserts to perform at one time, it is faster to do it with prepared statements, but rarely are there situations where the performance increase makes a difference. Most inserts are done one at a time, although it's always good to know that you have the option of doing a few if needed, and that those will be optimal. However, as Jacques1 stated, it's simply more secure to use the prepared statements and variable binding, and that's reason enough. You also lessen complexity, because you no longer have to worry about escaping strings.
  22. I don't see anything overtly wrong with the code, however, the update is always changing the row in the alert table with id = 1. The code that queries the alert table and displays it, does not select WHERE id = 1, but rather does a LIMIT 1 (limiting whatever the result set is, to only return one record). This could be the source of a subtle bug. Check your alert table with command line mysql or phpmyadmin. There might be more than one row in there, and could explain why you are seeing one row come up, even though you are updating the form with different values. The row that is being returned may not be the row that is getting updated. If this is the problem, to fix this code, change the SELECT queries in both scripts from: $... = mysql_query("SELECT * FROM alerts LIMIT 1"); to $... = mysql_query("SELECT * FROM alerts WHERE id = 1"); If this is not the problem, you would really need to put in debugging statements into the code to figure out what is going on.
  23. There is nothing magic about a sql statement, so if by omitted, you mean that it will take an empty variable and turn it into the string 'null', which is what the sql statment would be happy with, then that is not going to work. For example, if you start with these values: $val1 = "val"; $val2 = "val2"; $val3 = "val3"; $val4 = "null"; $val5 = "null"; Then you should get past your SQL error. Another solution is to put single quotes around the values, then mysql will probably convert that to a zero, and the statement will be accepted. However, I feel that all of these workarounds are missing the point, because you should be using prepared statements with mysqli. That would be of the general form: $stmt = $mysqli->prepare(... $stmt->bind_param('sssii', $val1, $val2, $val3, $val4, $val5); $stmt->execute(); Interpolating strings into sql statements is not good practice with mysqli or pdo, and can easily lead to sql injections.
  24. You can't concatenate a logical block onto a string. Instead, you should end your string, then evaluate the block and append to the string as needed. $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root">'; if ($account == "c") { $user .= '<li> <a href="/stats.php">Dashboard</a> </li>'; } Please look into templating, even if that is simply via includes, as well as alternative PHP syntax. PHP already allows you to intermingle PHP and HTML, and with heavy HTML like this, the approach you are taking is difficult to read and maintain.
×
×
  • 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.