Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. Try changing this: $query = "SELECT SUM (IF(department = 'science', 1, 0)) AS science, SUM(IF(department = 'art', 1, 0))-> AS art FROM new2"; To this: $query = "SELECT SUM (IF(department = 'science', 1, 0)) AS science, SUM(IF(department = 'art', 1, 0)) AS art FROM new2"; Note that I removed the "->" before " AS art".
  2. Just to clarify, in both case you only have one script. As for your question, I don't think it matters too much whether you just surround PHP code with PHP tags...or if the entire script is enclosed in PHP tags. Personally, I find scripts that constantly jump in and out of PHP harder to follow. However, I have written quite a few scripts that do just that. I guess it all depends on the ratio of HTML to PHP code. In case you're interested, more information about PHP tags can be found here: http://php.net/manual/en/language.basic-syntax.phptags.php
  3. Have you tried opening your browser's Console panel to see if there are any page or JavaScript errors? In Chrome, for example, you can hit Ctrl + Shift + J to open the Console. You can also right-click the page and click "Inspect Element" to access the Console.
  4. It's difficult to tell what's going on without the JavaScript. Can you post the code? Also, is there a reason you're not using the anchor (<a>) tag? Perhaps the JavaScript code adds the tag dynamically. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
  5. Is PHP set to display all errors and warnings? Adding the following debugging lines to the top of your script should make sure errors and warnings are being displayed: <?php //REPORT ALL PHP ERRORS error_reporting(E_ALL); ini_set('display_errors', 1); ?> Also, the debugging statement was an example. You can add these statements throughout the script to see where the program is getting stuck. The statements can also be used to view the contents of the variables which may be helpful for tracking down the bug. Of course, you may want to start at the beginning of your script with the debugging statements. Once you know the first one works, move on to the next and continue until the problem is found. You may want to remove or comment out the debugging statements when they are no longer necessary. That way it's easier to remove them when the program is fixed.
  6. I have yet to use .htaccess in this capacity, so I'm only guessing here. Have you looked into redirecting the incoming links that have the .php extension? Perhaps you can use redirectMatch 302 (temporary redirect) or 301 (permanent redirect)? Here's an example that seems applicable: http://www.lorem.biz/redirect/htaccess-new-file-extension.php Also note that using the raw value from $_SERVER['PHP_SELF'] isn't recommended since it opens your website to XSS attacks. More information can be found here: http://seancoates.com/blogs/xss-woes
  7. The PHP manual says to add an exit statement after calls to the header() function to prevent further code from executing. So this: if($row['check'] == 1) { header('location:/maintenance/'); } Should be this: if($row['check'] == 1) { header('location:/maintenance/'); exit; } If that doesn't fix the issue, have you tried adding debugging statements to see what aspects are being executed? For example, you could comment out the header() function and add an echo statement to see if your if test is passing when it should. if($row['check'] == 1) { echo '<div>Execute maintenance redirect</div>'; //header('location:/maintenance/'); exit; }
  8. The function returns a result object. More information can be found here: http://php.net/manual/en/mysqli.query.php Does the login script have another function for looping through query results? If not, you could create a loop like you would do for any other query. A loop could be created using mysqli_fetch_assoc(), for example: http://php.net/manual/en/mysqli-result.fetch-assoc.php
  9. The purpose of strip_tags() is to remove HTML and PHP tags from a string. More information can be found here: http://php.net/manual/en/function.strip-tags.php In your case, however, it looks you're running the email address(es) through something like htmlentities() before running strip_tags(). That's where entities like < come from. If you're just looking to remove some specific characters, you could look into using something like str_replace(): http://php.net/manual/en/function.str-replace.php
  10. For what it's worth, the following thread talks about redirecting URLs with a #: http://stackoverflow.com/questions/8910170/htaccess-redirect-does-this-work-for-all-anchor-links-in-page If that doesn't work, perhaps someone with more knowledge of .htaccess files can help.
  11. The header() function needs to be called before anything has been outputted to the screen. Do you still have the echo before the $_SERVER variable? If so, removing it should make the errors go away.
  12. With array_search(), you don't need the loop. <?php // Old Locations $OldPages[1] = 'page1.shtml'; $OldPages[2] = 'page2.shtml'; // New Locations Below! $NewPages[1] = 'newpage1.shtml'; $NewPages[2] = 'newpage2.shtml'; $key = array_search($_SERVER['REQUEST_URI'], $OldPages); if($key !== false) { header("HTTP/1.1 301 Moved Permanently"); header('Location: ' . $NewPages[$key]); exit; } ?> Of course, this may not work since the values in the $OldPages array are not root-relative values. Did you try echoing $_SERVER['REQUEST_URI'] to see if it matches a value in your array?
  13. $MaxPages would be a count of the entries in $OldPages. It used to loop through the entire array. However, you could use array_search() instead. More information can be found here: http://php.net/manual/en/function.array-search.php Basically, you could try something like this: $key = array_search($_SERVER['REQUEST_URI'], $OldPages); if($key !== false) { header("HTTP/1.1 301 Moved Permanently"); header('Location: ' . $NewPages[$key]); exit; } Note that I changed the second call to header() so that it redirects to the value in the $NewPages array. Otherwise you would be redirecting to the old page and end up in an infinite loop. Also, you may need to double check the value contained within $_SERVER['REQUEST_URI']. Make sure it matches the values used in the $OldPages array. To check the value, you can echo it: echo $_SERVER['REQUEST_URI'];
  14. Could you provide a little more information on your current setup? For all the broken links (old pages), do you have some sort of placeholder script which imports the redirect code pasted above? Also, are you unable to use an .htaccess file or are you just trying to avoid .htaccess for some reason? As for your script, is $MaxPages defined somewhere?
  15. When someone visits one of these broken links, are they brought to an 404 error page that you control? If so, you could modify the page to see which page the visitor attempted to view with: getenv('REQUEST_URI') From there you can execute a switch statement, if construct, database query, etc. to determine where to redirect the visitor.
  16. How are you testing to see if the media query(ies) work? Are you adjusting a browser window...or are you testing on a mobile device? If you're testing on a mobile device and it's an iPhone, you'll need to add a <meta> tag to get things working. Perhaps the following article will help: http://www.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/ If you scroll down a bit, there is a section for "Testing in an iPhone" which talks about the <meta> tag.
  17. Instead of maintaining two separate footer files, have you considered creating one and adapting it using CSS media queries?
  18. Perhaps the following tutorial on JOINS will help: http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php If you can get the JOIN figured, you should be able to calculate the totals with COUNT. Here's an example of someone using both JOIN and COUNT: http://stackoverflow.com/questions/19301398/php-mysql-left-join-count-column-same-id
  19. You could format the output from the date() function so it contains some sort of separator. Then just use explode() to break apart the date. More information about both functions can be found in the PHP manual: date() - http://php.net/manual/en/function.date.php explode() - http://php.net/manual/en/function.explode.php Side note: the split() function has been deprecated.
  20. There may be a way to merge some of the queries to avoid executing them within loops as ginerjm suggested. If MySQL isn't your strong suit, you could look into collecting the information into a multidimensional associative array. Here's a quick example showing the code I've used for a similar issue: http://www.cyberscorpion.com/2013-05/avoid-mysql-queries-within-loops/
  21. You'll need to add a test to make sure the denominator isn't zero before performing the equation. Perhaps you'll find a workable solution here: https://www.google.com/webhp#q=php%20division%20by%20zero
  22. You have quite a few queries which are executed within loops. This has a negative effect on performance.
  23. How is the date stored in the "host_payments2014.payment_paid_timestamp" field? It sounds like it's stored as a plain string instead of a date. More information about dates in MySQL can be found here: http://dev.mysql.com/doc/refman/5.0/en/datetime.html
  24. No problem; glad to help!
  25. The calls to mysql_real_escape_string() need to be made after the database connection has been established. Try moving them after the following line: include('connection.php'); Side note: in case you're not aware, the mysql_* function have been deprecated and will be removed in a future version of PHP. If you haven't done so already, you'll need to look into the alternatives at some point: http://php.net/manual/en/mysqlinfo.api.choosing.php
×
×
  • 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.