Jump to content

Jacques1

Members
  • Posts

    4,207
  • Joined

  • Last visited

  • Days Won

    209

Everything posted by Jacques1

  1. None of this requires str_split(). Just iterate over the characters: <?php $input = '1234'; for ($i = 0; $i < strlen($input); $i++) { $char = $input[$i]; var_dump($char); }
  2. The example output you claim to need isn't JSON. If you want JSON, use json_encode() together with the right Content-Type header: <?php header('Content-Type: application/json'); $data = ['a' => 1, 'b' => 2]; echo json_encode($data);
  3. The former is procedural, the latter is object-oriented. Choose whatever suits your application and personal preferences. Functionally, they're equivalent, which is why the manual always mentions both approaches. If you already rely heavily on object-orientation, it makes sense to go all the way. Otherwise use the classical PHP functions.
  4. Why? What are you trying to do?
  5. Write a coherent problem description with specific information (error messages, observations, things you've tried), format your code properly with code tags, and then we might be able to help you. The mysql_* functions you're using are obsolete since more than a decade and have been removed from recent PHP versions.
  6. password_hash() requires an algorithm and should be called with specific parameters: <?php const PW_HASH_ALGORITHM = PASSWORD_BCRYPT; // bcrypt is the de-facto standard and currently the only choice const PW_HASH_COST = 14; // adjust this to your own needs $password = 'test'; $hash = password_hash($password, PW_HASH_ALGORITHM, ['cost' => PW_HASH_COST]); var_dump($hash);
  7. Write a coherent problem description (preferably with actual code), then we might be able to help you.
  8. All you have to do is turn your brain back on and describe the problem in plain English. Something like: “I've tried to insert a new user with the values ..., but when I check the record in the database, all fields are empty”. Is it so hard? But since you're hoplessly confused, and since the approach is generally poor, I suggest you scrap the code and start over. For example: // TODO: distinguish between required and optional attributes const USER_ATTRIBUTES = ['name', 'username', 'password', 'email', /* ... */]; public function addNewUser(array $data) { $values = []; foreach (static::USER_ATTRIBUTES as $att) { if (!isset($data[$att])) { throw new InvalidArgumentException('Missing user attribute: '.$att); } $values[] = $data[$att]; } $addQuery = ' INSERT INTO users ('.implode(',', array_values(static::USER_ATTRIBUTES)).') VALUES ('.implode(',', array_fill(0, count(static::USER_ATTRIBUTES), '?')).') '; $this->attachValues($addQuery, $values); } private function attachValues($sqlQuery, array $params = []) { if ($params) { $stmt = $this->database->prepare($sqlQuery); $stmt->execute($params); } else { $this->database->query($sqlQuery); } }
  9. What – is – the – problem? Or did you just want to tell us that it's fine now? Also read #4.
  10. What exactly is the problem? Actually, why don't you just fix your database and add the missing default values? Also note that your function has no protection against SQL injection attacks through the array keys. A far more secure and robust approach is to explicitly write down the columns in the query. This not only prevents injection attacks. It also protects columns which should never be manually defined (like auto-incremented IDs).
  11. This tells us absolutely nothing. I know the code “doesn't work”, otherwise you wouldn't be here. The question is: What exactly is the problem? Be specific. What goes wrong when? Are there any PHP or JavaScript errors? What do the developer tools of your browser tell you about the HTTP communication? We're not sitting in front of your screen. We don't have your application on our PC. We know nothing except what you tells us. So if you want help, you need to actually provide information.
  12. The code is badly fudged up. You have a random mixture of mysqli_* calls and mysql_* calls (copy-and-paste, I guess), you overwrite your own Location headers because you never stop the script. And the plaintext passwords are hopefully just a bad joke. I'm fairly sure the code does nothing but fill the PHP error log with messages (which you should check, by the way). You should scrap it, learn PDO and start over.
  13. It doesn't make sense to hire a programmer when it's a problem with the data. In the worst case, you'll pay a lot of money for useless workarounds. If it's too late to fix the database itself (which is probably the only real solution), you can at least fix the query: SELECT DISTINCT IF(sn_School1 <> '', sn_School1, sn_School2) AS school FROM user_info ORDER BY school ASC Since I don't know your data, I'm guessing here. Maybe your "empty" actually means NULL rather than an empty string.
  14. That was more than three years ago, and the user hasn't been online ever since. Create your own threads, don't hijack or resurrect old topics.
  15. Help you with what? You haven't even told us what the problem is. Until then, all I know is that your database queries are messed up. First you use a prepared statement and manual escaping at the same time, which will screw up the data. Then you use neither, which will lead to security vulnerabilities. Use prepared statements; no manual escaping, no unprotected queries. The code is also vulnerable to cross-site scripting attacks. You need to HTML-escape strings before you can insert them into your page.
  16. And why are there two columns for the school? Right now, it sounds like you need to repair your database, not write any code. After 11 years?
  17. This is a help forum, not a We-write-code-for-random-people-on-the-Internet forum. You are expected to turn your brain on and actively work on the problem. If you do that, you're welcome. If you're just here to show off your laziness and lack of respect, you should go somewhere else.
  18. Why is that an issue?
  19. The code alone doesn't tell us anything. We need concrete information, which is why I'm asking you to insert var_dump() statements into your code and tell us the exact content of $_POST['comment'] and $comment. Are you sure the comment box in the contact form is a text field with the name comment?
  20. “Doesn't work” isn't sufficient information. What exactly is the problem? Is $_POST["comment"] set at all? What's the content of $comment? Use var_dump() to check this. Are there any error messages in the PHP log? The code in general doesn't make a lot of sense. For example, you check if the client used the POST method (you even do it twice, for some strange reason), but you never actually check if the specific fields are present, and you send the e-mail in any case. If I simply visit the page and reload it a couple of times, you end up with dozens of empty e-mails in your inbox. I assume this is all copied and pasted from different websites? While I can understand that you're a beginner who just wants to get things done, this approach will lead to very bad code and is a dead end. You should learn the language and write your own code. Even if it won't be perfect at first, you'll at least understand what's going on and make progress.
  21. You haven't attached anything, but you have marked the problem as solved, which means you longer need help. So, case closed? Or are you having trouble with the user interface?
  22. PHP: Supported Versions
  23. PHP 5.3 was abandoned years ago and doesn't even receive security updates. Either get your hoster install a current PHP version (5.6 or at least 5.5), or get a new hoster. In this particular case, I suspect it's the short array syntax. But like I said, there are much more serious problems. PHP 5.3 is dead.
  24. This is not how JSONP works. Why did you choose it, anyway? JSONP is a horrendously insecure legacy hack. Unless you specifically need to support ancient browsers, use CORS instead.
×
×
  • 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.