Jump to content

ManiacDan

Staff Alumni
  • Posts

    2,604
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by ManiacDan

  1. Barand's solution was very dangerous and not recommended (as he noted in his post). While it gets your site working today, your site still has security problems that are more than a decade old. You should rewrite this with modern best practices, in PHP 5.4.
  2. This is a super old thread at this point, but congratulations!
  3. When posting code, surround it in [ PHP ] and [/ PHP ] tags, without spaces inside the tags. That's how you color your code and make it easier to read. Your error message indicates that your query it malformed. Then it prints the query. As you can see, your query is missing the value for student ID. That's because you never get the value for studentid from anywhere. Your code initially uses it here: $_SESSION['studentid'] = "$studentid"; (This variable doesn't need to be quoted in this line) You are relying on an old feature of PHP called register_globals. I have bad news for you: Every single one of your pages is probably broken. Your code was assuming there was a key called 'studentid' in $_GET, $_POST, or $_COOKIE. You have to figure out which one, and put this at the top of your file: $studentid = $_POST['studentid']; You then need to repeat this exercise with every single variable you use this way. On every page, in every file. You upgraded your PHP install without knowing how it would work. It's like upgrading your operating system. Some of your apps will stop working. In your case, you were doing something critically wrong and nobody told you until it was too late. Good luck, you have a lot of changes ahead of you.
  4. Just in case it takes 3 people to say it: You are doing this wrong. You cannot store comma-delimited lists in a single column. Why not? Because of this thread. It causes this problem. This problem cannot be solved. Your database is not designed right.
  5. There's nothing else in this file, and you're sure this is the file being included?
  6. So instead of base.css I get Foo.php again? That doesn't make much sense. Or do you mean you're getting a 200OK with no content?
  7. Your first error is "there is no database." Your second error is "your database connection file is wrong." Read the error. Look at it: Fatal error: Cannot redeclare connecttodb() (previously declared in docroot/dblib.php:9) in docroot/dblib.php on line 22 What happened? "Fatal error" Why? "Cannot redeclare connecttodb()" Why not? "(Previously declared in docroot/dblib.php:9)" Where did this error happen? "in docroot/dblib.php on line 22" the error message is as exact as it can possibly be without spelling it out in 3 paragraphs like I'm doing. Your connecttodb function occurs twice. You can't have two copies of the same function. You must fix your dblib.php so it only has one function, and make sure that function is correct. Then you must include your dblib in any script which wishes to use the database, and ensure the database connection is actually established before you try to use it.
  8. It absolutely should not have a .php extension if it's not php code. You need to simply open a new file handle for each destination. Your code here, which I've already shown you, opens one copy of the file: $Fnm = "./include.php"; $inF = fopen($Fnm,"w"); Do that exact same thing, but make $Fnm a different path. Your awfully named $folder2 and $file6 and all those should contain some semblance of the proper directory structure to use in fopen.
  9. Why are you doing this? What is the purpose? You can accomplish selective directory listing using apache settings directly.
  10. Is there any particular reason you WANT to do this? All date/time functions accept a timestamp as an argument. If one is not provided, it uses "now." You could write your script to have a test flag which will override the value of every date function.
  11. It's only available in PECL (which I don't have installed) so you'll have to check the behavior of it yourself for user-defined functions. There is also rename_function, which may work for you.
  12. The actual answer to your question: You appear to only write to one file, which is: $Fnm = "./include.php"; $inF = fopen($Fnm,"w"); Put the folder definitions in the $Fnm and you should be fine. You may have to make the directory first. Other comments: Whatever you're doing here is probably wrong, I bet you can do this much easier another way if you tell us why you need to do this.
  13. Why not just go to youtube?
  14. I disagree. PHP was not meant to be a strictly typed language, and a lot of things wouldn't work in their current state if it was. There are many other languages that follow suit. I don't think it is a huge deal. As long as you understand the difference between == and ===, you shouldn't ever have any problems. I'm with you. Most of the complaints about PHP stem from either (a) not understanding loosely typed languages or (b) not understanding symbol tables. PHP is loosely typed. == is not ===. If you really really care about data types (like in this specific scenario), use ===. Otherwise, == is magical. Empty strings, zero, negative one, false, empty objects, empty arrays, whatever. "not something" a very powerful concept.
  15. Use PHPMailer, it handles most of the hard parts for you. There are tutorials available for it. Be sure to set the FROM and REPLY-TO headers using the built-in functions.
  16. Barand is correct about strpos, but strstr works differently. Strstr returns the matched string. All three of these examples worked for me: php > $a = '123@456'; php > $b = '123@ 456'; php > $c = '123 @ 456'; php > var_dump(strstr($a, '@') == true); bool(true) php > var_dump(strstr($b, '@') == true); bool(true) php > var_dump(strstr($c, '@') == true); bool(true) php > var_dump(strstr($a, '@')); string(4) "@456" php > var_dump(strstr($b, '@')); string(5) "@ 456" php > var_dump(strstr($c, '@')); string(5) "@ 456" I'm not sure why you think it wasn't matching with the space after it for strstr. Either way, strpos !== false is what you want. Make sure you realize that !== is correct, and != is incorrect. === and its counterpart !== are required here, not ==.
  17. I'm not really frustrated, I just honestly have no idea what you're even doing anymore. You have two scripts now which do two things you may or may not need. I don't know what you're using which requires tab delimited strings rather than a normal, sane data structure like an array, but good luck with it. If this is still not what you needed, go back and state the problem more concisely. What do you have? What do you need? Why do you need it that way?
  18. What is the actual problem then? What is "the formatting part"? You said: Did this have nothing to do with CSV output? Are you just looking to replace a single \n with \t as long as there aren't two \n\n? If that's the case: $str = str_replace("\n\n", "__DOUBLE_NEWLINE__", $str); $str = str_replace("\n", "\t", $str); $str = str_replace("__DOUBLE_NEWLINE__", "\n\n", $str);
  19. "Address" is spelled wrong, that just bothers me because you'll never know the names of your functions if they're all spelled wrong. Define all your functions in the global scope at the top of the file (or in a separate include file) so you know they're always accessible.
  20. 1) You can use a database just like you'd use a text file, using a database gets rid of your delimiting problem entirely, just insert it into the database. Whether or not the paste into a textarea is irrelevant, you can insert anything you want into a database. 2) Encoding something using base64 (or whatever) will also avoid your encoding problem. You said you were having issue with \n\n and \t and how they'd interact with the csv format. Just keep them in whatever format you want, and encode them. the encoded data will be compatible with csv format, and the decoded data would still have newlines and tabs however you'd like them.
  21. Post the solution so that others may benefit. Also, mark it as "solved." The answer, for anyone who comes across this, is: 1) Use alternate delimiters. Regular expressions don't have to start and end with /. You can use any non-alphanum character, like # or even {}. 2) Escape the slash, like so: /.+\/.+/
  22. fputcsv deals with a pre-existing resource handle, not a pre-existing file. Using fopen you can create a new file. The correct answer is "use a database." If you can't for whatever reason, you can encode the questions and answers so they're sure not to contain quotes or whitespace. base64_encode every field and you won't have a problem.
  23. Sending mail that isn't spam is a very difficult process. Depending on the volume your answer is anything from "use PHPMailer and set the reply-to header" to "hire a spam mail expert and establish business relationships with the 10 largest email hosts"
  24. It's your page, not mine. Change the colors, make it bold, whatever. You "do it with CSS" the same way you do anything with CSS: give it a special class. This...makes no sense, but again, it's your site and not mine. How do you determine which page you're on? However you determine that (url, filename being called, a variable called $page), check that against the nav items you're printing when you print them. If the page you're on matches the nav item you're about to print, make it a different color or size or whatever.
  25. No reason to make that a PHP extension, it would be too slow to parse a PDF every time. It should be a standalone application. However, PDF creation tools are pretty locked down to Adobe products. Maybe their PDF library actually does that.
×
×
  • 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.