Jump to content

Jacques1

Members
  • Posts

    4,207
  • Joined

  • Last visited

  • Days Won

    209

Everything posted by Jacques1

  1. What is your question? What have you tried, and what exactly “isn't working”? If you want us to write the HTML markup for you, this won't happen. We can help you with specific questions, but we don't do your job.
  2. A local variable of a function isn't visible outside of the function. So you cannot create a $conn variable inside your function and then access it in the main script. The best solution in this case is to return the PDO instance: function mysqlconnect($host, $username, $password, $database, $character_set) { $dsn = 'mysql:host='.$host.';dbname='.$database.';charset='.$character_set; return new PDO($dsn, $username, $password, [ PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } Hard-coding the connection parameters into the function is not a good idea, because then you cannot easily change them. You should have a configuration script where those parameters are defined and then pass them to the above funciton.
  3. OK, now we at least know what the task is. My suggestion in post #4 will solve this problem. If you don't now how to implement it, show us what you've tried and explain exactly what you don't understand. In any case, you do need basic PHP and programming knowledge for us to have to discussion. If you don't know how to create an array or write a loop, this isn't the right place. You should start with Codeacademy or buy a book.
  4. When you want help, post your real problem. Don't make up some bullshit fantasy example, because this is almost guaranteed to fail miserably. So what you actually want to do is check if the input contains a string from an array. The strpos() function searches a single substring within a single string. If you combine that with a loop, you can search for multiple words and print the matches.
  5. Wut? So you have a list of names (for whatever reason), a user enters their name, and now you want to map the chosen name to a vaguely similar predefined name. According to which rules? Does "alex" map to "alexa"? Does "tixxxna" map to "tina"? And why on earth are you doing this? Is it just a random exercise you've come up with?
  6. So did you solve the problem? If not, what is the problem? Be specific and post the real code. Providing fantasy code is a very bad idea when you expect real answers.
  7. You should collect those values in an array, not pass them individually. So kicken's suggestion is correct, except that you need to add a third case (an empty array) for when there are no values at all. And I see you're still pre-rendering your HTML options in edit_membership.php. Get rid of this, it's entirely unnecessary.
  8. I'm not sure what you're asking. Yes, you can make some fields mandatory and some fields optional simply by implementing the validation logic accordingly (an empty required field leads to an error, an empty optional field doesn't). And, yes, you can pre-fill the form with existing values that are stored e. g. in the database.
  9. The :$desc1, ... parameters are broken. Remove the dollar sign.
  10. The loop doesn't do anything but overwrite the same variables over and over again. How is this supposed to work?
  11. None of your form fields has a name. I suggest you comment out the mail() call and simply print the message until you have a basic understanding of PHP. The script in general is very poor and has plenty of security vulnerabilities. You don't even check if anything was submitted at all, which means you get an empty e-mail whenever a human or bot has visited the URL. And what's with the stripslashes()? Magic quotes don't even exist today, so that code you've appearently copied and pasted from somewhere is ancient.
  12. PHP doesn't just crash for no reason. Have you checked the error log of IIS? Errors don't necessarily pop up on the screen, but they do get logged -- unless your PHP configuration is completely broken.
  13. You aren't passing any post key to the template. 'post' => $_POST Use dump() for debugging.
  14. Check the PHP error log. The sqlsrv_* functions may not be available in your current setup. In generally, I don't recommend using MS SQL, unless you absolutely must. Compared to a common open-source database system like MySQL/MariaDB or PostgreSQL, you'll have a lot more trouble and a lot less support. If you do choose it, be prepared for your own research. He's using Windows Authentication, and even if the function fails, this doesn't crash the whole script.
  15. The null-coalescing operator ??. value="{{ post.membership_type ?? '' }}" Or a simple if statement with defined as in #8.
  16. Do the validation in the PHP script, then pass the $error array to the template.
  17. Use a plain if statement. {% if id is not null %}<input type="hidden" name="id" value="{{ id }}">{% endif %}
  18. The mail() function is archaic and known to cause trouble, because it relies on a local Sendmail program. If your server doesn't have that, or if you're not allowed to use it, or if the server isn't authorized to send e-mails directly, you're out of luck. Use a professional library like PHPMailer and relay the e-mails through the account which already worked. For example, if you're using Gmail, pass the Gmail SMTP server and your credentials to the library.
  19. The image is still nonsense. Have you considered clicking on the link I just gave you and reading the explanations? I know, it sounds crazy, but try it. And then there's Google. It took me exactly 10 seconds to find a Stack Overflow thread explaining exactly how to remove the border.
  20. It doesn't work like this. You have to actually learn CSS.
  21. If you want the client to open the file rather than just download it, leave out the "Content-Disposition" line.
  22. I've given you the exact code, so how can you be lost now? What's the problem?
  23. You do not pre-generate the HTML form elements, because now you're back mixing business logic with rendering. You simply pass the people array and the selected person (or $_POST) to the template and let it generate the options. <?php $people = $pdo->query('SELECT person_id, first_name FROM people')->fetchAll(); // pass $people and $people_id (or $_POST) to the template <select id="person_id" name="person_id" class="form-control"> <option value="">Select Person</option> {% for person in people %} <option value="{{ person.person_id }}" {% if post.person_id is defined and post.person_id == person.person_id %}selected{% endif %}>{{ person.first_name }}</option> {% endfor %} </select> Or you create a macro (not a function) to build the menu from an array of values.
  24. What is the field supposed to do? Is it just a dumb text field, or do you want an autocomplete or combobox feature as the <select> indicates? jQuery UI has a large variety of different form elements which you should look at before rolling your own.
  25. The proper way (not just for Twig) is to untangle the business logic and presentation. Executing queries is business logic and belongs into the underlying PHP script; the template is only responsible for rendering, so it shouldn't do anything but receive the result set and generate the corresponding HTML markup. What I personally find helpful is to imagine that there must be multiple output formats like HTML for humans and XML for bots. Right now, this is unthinkable, because everything is one big block of PHPSQLHTMLCSS. You can't just switch to XML. But if you separate the different layers and use templates exclusively for rendering, you can provide any output format simply by using a different template.
×
×
  • 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.