Jump to content
eduard

Explain nr 3?

Recommended Posts

Can someone explain nr. 3 please?1) create database and table (it's probably just easier to do this in phpMyAdmin) for your products and add fields for every piece of information you want to save about a product (price, description, stock, etc). You've already done this and we've already help you. Please refer to the tutorials and your past threads. Nothing overly complicated about this at all.* http://www.w3schools.com/php/php_mysql_connect.asp* http://www.w3schools.com/php/php_mysql_create.asp2) HTML - create a form that has inputs so that it can submit data to a PHP script to save the information from the form to a database. The form inputs should match the fields you've made in the table.* http://www.w3schools.com/html/html_forms.asp3a) PHP - create a script that takes in a $_POST or $_GET array for submitting form data to the database* http://www.w3schools.com/php/php_forms.asp* http://www.w3schools.com/php/php_get.asp* http://www.w3schools.com/php/php_post.aspb ) PHP/SQL - once you have the form submitting to the PHP script, and you can view all the data, you are ready to write an INSERT query to submit the information to the database* http://www.w3schools.com/php/php_mysql_insert.asp---after that's all done, and you've gotten that process to work and have saved a few products, you should see them show up in phpMyAdmin, as you add them4) PHP/SQL/HTML - create a PHP file that SELECT's records (products) from your table and outputs them to the browser in the form of HTML markup* http://www.w3schools.com/php/php_mysql_select.asp

Edited by eduardchile

Share this post


Link to post
Share on other sites

In order for the user to pass data from a webpage to your PHP script, they need to submit it via a form. The form offers 2 methods of doing this, POST and GET..GET is imbedded in the URL (example: http//www.yoursite.com?data=input_from_the_user).POST is invisible and its size limit is much higher.To manipulate this data in your script you need to use the two super global arrays $_GET and $_POST..When you have retrieved the data you can insert it into your database.It is very thoroughly explained in the tutorials. Can you be more specific as to what you're having troubles with?

Share this post


Link to post
Share on other sites
In order for the user to pass data from a webpage to your PHP script, they need to submit it via a form. The form offers 2 methods of doing this, POST and GET..GET is imbedded in the URL (example: http//www.yoursite.com?data=input_from_the_user).POST is invisible and its size limit is much higher.To manipulate this data in your script you need to use the two super global arrays $_GET and $_POST..When you have retrieved the data you can insert it into your database.It is very thoroughly explained in the tutorials. Can you be more specific as to what you're having troubles with?
I understand the meaning of it, but I´m just a beginner and I don´t understand I have to make a php script with the array $_get or $_post and I have to put this in a html form?

Share this post


Link to post
Share on other sites

Okay, below is the html code for a simple form. The two attributes action and method are very important. The action attribute will determine where the data will be sent and the method attribute will determine how the data is sent.

<form action="welcome.php" method="post">Name: <input type="text" name="fname" />Age: <input type="text" name="age" /><input type="submit" /></form>

The above form will send the data to "welcome.php" and it will be sent with the "post" method. Notice the two inputs Name and Age. These inputs have the names "fname" and "age". When the user enters his/her name and age and clicks the submit button, the user will be sent to the "welcome.php" page. On this page you will have a script to retrieve the information just sent by the user. Look at the code below.

// welcome.php<?php$name = $_POST['fname'];$age = $_POST['age'];echo "Hello " . $name . ". You are " . $age . " old!";?>

Remember the input names? In the code above the information which was sent to the script is saved in the variables $name and $age. After the information has been stored in the variables, it is echoed and displayed in the browser.

Share this post


Link to post
Share on other sites
Okay, below is the html code for a simple form. The two attributes action and method are very important. The action attribute will determine where the data will be sent and the method attribute will determine how the data is sent.
<form action="welcome.php" method="post">Name: <input type="text" name="fname" />Age: <input type="text" name="age" /><input type="submit" /></form>

The above form will send the data to "welcome.php" and it will be sent with the "post" method. Notice the two inputs Name and Age. These inputs have the names "fname" and "age". When the user enters his/her name and age and clicks the submit button, the user will be sent to the "welcome.php" page. On this page you will have a script to retrieve the information just sent by the user. Look at the code below.

// welcome.php<?php$name = $_POST['fname'];$age = $_POST['age'];echo "Hello " . $name . ". You are " . $age . " old!";?>

Remember the input names? In the code above the information which was sent to the script is saved in the variables $name and $age. After the information has been stored in the variables, it is echoed and displayed in the browser.

Thank you very much!

Share this post


Link to post
Share on other sites

Can I write this?<form action="Database table PRODUCTS" method="get"> or must "Database table PRODUCTS" be a php file? What should this file be e. g. products.php?

Edited by eduardchile

Share this post


Link to post
Share on other sites

The form action should be the URL of the PHP script (or other script) that you want to handle the form submission.

Share this post


Link to post
Share on other sites
The form action should be the URL of the PHP script (or other script) that you want to handle the form submission.
Thanks! But how about it if my database and tables are created in phpMyAdmin? Edited by eduardchile

Share this post


Link to post
Share on other sites
Thanks! But how about it if my database and tables are created in phpMyAdmin?
It doesn't matter how your database was created, you still need to write a PHP script to interact with it.

Share this post


Link to post
Share on other sites

Why would it make a difference how the tables are created? Your browser isn't accessing the database, the PHP script is.

Share this post


Link to post
Share on other sites

However, if I want to ´get´ the description, the price and the quantity of a product! How do I write that as a php script?

Share this post


Link to post
Share on other sites

form action is the URL of the table (products) of the database (company) which is saved in phpMyAdmin?

Edited by eduardchile

Share this post


Link to post
Share on other sites
However, if I want to ´get´ the description, the price and the quantity of a product! How do I write that as a php script?
You use a SQL SELECT query to get the data you're looking for from the database and output it. Look at the tutorials for examples of using SELECT queries.
form action is the URL of the table (products) of the database (company) which is saved in phpMyAdmin?
No, it's the URL of a PHP script you wrote to do whatever you want with the data in the form. The table and database do not have URLs, they are managed by MySQL. The form on your page has nothing to do with phpMyAdmin.

Share this post


Link to post
Share on other sites
You use a SQL SELECT query to get the data you're looking for from the database and output it. Look at the tutorials for examples of using SELECT queries.No, it's the URL of a PHP script you wrote to do whatever you want with the data in the form. The table and database do not have URLs, they are managed by MySQL. The form on your page has nothing to do with phpMyAdmin.
Thanks!

Share this post


Link to post
Share on other sites

But has this MySQL page be connected with my database in phpMyAdmin?

Share this post


Link to post
Share on other sites

There's no such thing as a "MySQL page". We've gone over this many times, but let's go over it again. If you don't understand what I'm about to say, tell me what you don't understand, and why you don't understand it.You make a PHP script. It doesn't matter what the name is. It starts with no code, because you write all of the code. Your PHP script uses the mysql_connect function to make a connection to the database.Once the script is connected to the database, you use the mysql_query function to send queries to the database and get the results back.Notice there is nothing there about phpMyAdmin. Your form and your PHP script which processes the form do not use phpMyAdmin at all. You are the only thing that uses phpMyAdmin when you log in and create the database or run queries. The code you write does not use phpMyAdmin. Ever. For anything.If you don't understand any of that, before you ask any other questions, tell me what you don't understand and why.

Share this post


Link to post
Share on other sites
However, if I want to ´get´ the description, the price and the quantity of a product! How do I write that as a php script?
just read the tutorials. In the same fashion as the others your script connects to database. This time instead of INSERTING into a table, you SELECT from a table.

Share this post


Link to post
Share on other sites
There's no such thing as a "MySQL page". We've gone over this many times, but let's go over it again. If you don't understand what I'm about to say, tell me what you don't understand, and why you don't understand it.You make a PHP script. It doesn't matter what the name is. It starts with no code, because you write all of the code. Your PHP script uses the mysql_connect function to make a connection to the database.Once the script is connected to the database, you use the mysql_query function to send queries to the database and get the results back.Notice there is nothing there about phpMyAdmin. Your form and your PHP script which processes the form do not use phpMyAdmin at all. You are the only thing that uses phpMyAdmin when you log in and create the database or run queries. The code you write does not use phpMyAdmin. Ever. For anything.If you don't understand any of that, before you ask any other questions, tell me what you don't understand and why.
Thanks!The only question I have now: I want to show the queries and their output on my website!and therefore I have to write the php script(s) on a html page?

Share this post


Link to post
Share on other sites

For the sake of simplicity, yes, you write the PHP script on an HTML page.In reality, it's a PHP script that outputs HTML, but you can think of it as a PHP script on an HTML page if that helps.

Share this post


Link to post
Share on other sites
For the sake of simplicity, yes, you write the PHP script on an HTML page.In reality, it's a PHP script that outputs HTML, but you can think of it as a PHP script on an HTML page if that helps.
but to just reinforce past information given, no matter which way you think about it, the page must end in .php.

Share this post


Link to post
Share on other sites
but to just reinforce past information given, no matter which way you think about it, the page must end in .php.
Thanks!

Share this post


Link to post
Share on other sites

Is this allright?<?php$description = $_POST['description'];$price = $_POST['price'];$quantity = $_POST['quantity'];echo "The description, price and quantity" . $description . $price . $quantity . "of a product"?>

Share this post


Link to post
Share on other sites
What happens when you run that? Does it do what you expect?
No, these are the errors (MAMP):But I don´t understand them!Notice: Undefined index: description in /Applications/MAMP/htdocs/test/get.php on line 3Notice: Undefined index: price in /Applications/MAMP/htdocs/test/get.php on line 4Notice: Undefined index: quantity in /Applications/MAMP/htdocs/test/get.php on line 5The description, price and quantityof a product

Share this post


Link to post
Share on other sites

That means that, for example, $_POST does not have an item called 'description'. If you want to see everything that is in $_POST, you can use print_r:echo '<pre>' . print_r($_POST, true) . '</pre>';That will print the structure of $_POST and show you everything it has in it. If you want to check if those exist to avoid the error, you can do this:$description = isset($_POST['description']) ? $_POST['description'] : '';That is the same as this:

if (isset($_POST['description']))  $description = $_POST['description'];else  $description = '';

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...