-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
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
-
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.
-
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.
-
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".
-
Can someone guide what's the error in this code?
cyberRobot replied to Cloud_Geek's topic in Other RDBMS and SQL dialects
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. -
No problem. Glad you got everything figured out!
-
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
-
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.
-
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.
-
Error session variable not displaying message in another php file
cyberRobot replied to Alexa's topic in PHP Coding Help
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. -
Try adding echo before the variable.
-
Error session variable not displaying message in another php file
cyberRobot replied to Alexa's topic in PHP Coding Help
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. -
Error session variable not displaying message in another php file
cyberRobot replied to Alexa's topic in PHP Coding Help
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. -
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 ... )
-
What does your form code look like?
-
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
-
How do you use arrays to display a form??
cyberRobot replied to slotegraafd's topic in PHP Coding Help
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>'; -
How do you use arrays to display a form??
cyberRobot replied to slotegraafd's topic in PHP Coding Help
What does your current code look like? -
How do you use arrays to display a form??
cyberRobot replied to slotegraafd's topic in PHP Coding Help
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. -
How do you use arrays to display a form??
cyberRobot replied to slotegraafd's topic in PHP Coding Help
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? -
Welcome!