Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. It depends. What are you looking to accomplish? Do you have any experience with HTML? What method of learning works best for you? There are many books that might help, if you're just getting starting. Or I'm sure there are a number of in-depth tutorials online, if you learn better that way. For what it's worth, I regularly use the HTML help docs found on the following Mozilla website: https://developer.mozilla.org/en-US/docs/Web/HTML They do have a few different guides that could get you started here: https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML
  2. Based on the code provided, $user is only being set if the SESSION variable for "username" is set. If you haven't already, I would check to see what that SESSION variable contains when you're getting the error. It's difficult to tell how you should proceed with the information provided. In the end, you'll likely need to test whether $user is set before trying to use it. How you do that depends on the purpose of the page and how your script is set up.
  3. Those are just sample category names. Yours should be +----+--------------+-----------------+ | id | topic_title | topic_parent_id | +----+--------------+-----------------+ | 1 | Authors | 0 | | 2 | General | 0 | | 3 | People | 0 | | 4 | Celebrities | 3 | | 5 | Historical | 3 | +----+--------------+-----------------+ ...etc.
  4. All you should need is the id, topic_title, and topic_parent_id. Where Barand uses "service", you would use "topic_title". Where Barand uses "parent", you would use "topic_parent_id".
  5. As Barand mentioned, the code (as posted) is technically fine. Just be aware that the missing semi-colon after the line that outputs "Green" may cause errors if you add more code to the PHP block after the final echo statement.
  6. No problem. Glad you got everything figured out!
  7. Does the query return an error? If so, what's the error? Or does the page display "New record has been added successfully !"?
  8. When naming the quantity fields, I would use the row ID from the database as the key that goes between the square brackets. If your "Cherry" product's ID is 5, for example, the input tag for the quantity field in the HTML code would look like this: <input type='number' min='0' max='10' name='quantity[5]' ... That way you don't need to pass the product names and prices with the form submission. And you don't need to worry about the customer trying to change a price on you in the form. Note that the "readonly" flag is very easy to bypass for someone who's familiar with the Console feature built into all the major browsers. After the form is submitted, the ID from the "quantity" array can be used to pull the necessary information from the database. The ID will also make it easier to redisplay the form, because you can access the necessary quantity value with the ID (e.g. $_POST['quantity'][5]). Side note: In case you're not aware, you'll want to use caution with using variables like in the following line: <input type='text' min='0' max='10' name='productName[]' value='$productname' ... Have you tried adding a product name that contains an apostrophe? It's going to cause problems with the form. The problem is potentially worse when that variable contains a value that can be tampered with by the user. See XSS attacks for more information. If you haven't done so already, you'll want to look into escaping variables for output. https://www.php.net/manual/en/function.htmlspecialchars.php
  9. You could potentially try setting a session variable (or cookie in PHP) and reload the page. If the session variable (or cookie) doesn't exists after the page reloads, you could display an error message to the user.
  10. In case it helps, the PHP manual mentions the alternative functions to use in the place of your various "mysql_" calls. You just need to look the functions up in the manual. For example, the following page talks about mysql_connect and the potential alternatives: https://www.php.net/manual/en/function.mysql-connect.php As gw1500se mentioned, the PDO alternative is going to be the way to go. Also note that the following page provides more information about migrating from PHP 5.6 to 7: https://www.php.net/manual/en/migration70.php Of course, there may be other changes you'll need to make since it sounds like you were using an even older version of PHP. Note that there are several links under the "Appendices" heading for migrating from/to different PHP versions. Unfortunately, I don't know if there is a way to merge the different links so you can get all the information at once.
  11. cyberRobot

    Hello!

    Hello and welcome!
  12. Just to make sure, for benanamen's suggestion, you should replace the following line: if(isset($_POST["submit"])) With the line below. Note that I removed the curly / smart quotes around POST. if($_SERVER['REQUEST_METHOD'] == 'POST') I would also add some sort of debug code to see if the if test is working. For example, if($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<br>form submission detected'; Does the script display "form submission detected" after submitting the form? Also, if the script still doesn't work as you expect, please post your most recent code.
  13. What was the problem that you noticed? Are you getting an error? If so, what is it? If you haven't done so already, it may help to set PHP to display all errors. You could add the following code to the top of login.php: //REPORT ALL PHP ERRORS error_reporting(E_ALL); ini_set('display_errors', 1); Just remember to remove the code when you are done debugging the script.
  14. Try adding some echo statements to your if constructs where you test the form input. That way you can make sure the code is executing properly. For example, you could try something like this: if(isset($_POST["submit"])) { echo '<br>form submission detected'; //process form if($_POST["username"] == "" || $_POST["password"] == ""){ echo '<br>either username or password is blank'; Note that you'll want to comment out or remove the session code in your login_view.php file to avoid errors caused by the above echo statements. That session code isn't necessary anyways since you already started the session in your login.php file.
  15. Try adding the following echo statement inside your if construct to see what $_POST contains: if (isset($_POST['login'])) { echo '<pre>' . print_r($_POST, true) . '</pre>'; After adding the line, try submitting the form, but don't use a real login. Just enter random characters. What does the output look like? Note that you're looking for output like the following (please don't post real usernames/passwords): Array ( [tpw] => sdflaje ... )
  16. What does your form code look like?
  17. Which "index" does the error message refer to? What is the error message? Side note: if you're not doing so already, you'll want to look into password security. More information can be found here: https://www.php.net/manual/en/faq.passwords.php
  18. Adding the following line of code inside your foreach loop may help with understanding what's inside $value: echo '<pre>' . print_r($value, true) . '</pre>';
  19. It sounds like you are trying to use an array key that doesn't exist. Are you using an associative array, like your first post above shows. Or are you using a numeric array, like benanamen's code uses? Your choice will affect how you use the keys within the loop that outputs the form fields.
  20. Where are you stuck? Creating the array or using the array to display the form? What have you done so far? What does your current code look like?
×
×
  • 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.