Hi,
you should get accustomed to using the
PHP manual when you're not sure about how something works:
PHP: switch - Manual
There's also Google and many, many tutorials. Most of them are exceptionally bad, but they tend to at least get the basics right.
To cut it short: You need a colon after "case ..." and "default", not a semicolon (which terminates a statement).
Apart from that, there are severe security problems with your code. When you just dump user input into SQL queries and HTML markup, you allow attackers to manipulate the queries and inject JavaScript respectively (known as
SQL injections and
cross-site scripting).
So you need to
prepare the user input first to make sure it doesn't get interpreted as actual code. In the case of HTML, you need to use
htmlentities() to escape special characters like "<". In the case of SQL, you need to use so called "prepared statements", which allow you to safely pass values to SQL queries.
Note that the old "mysql_" functions do not support prepared statements. These functions are generally obsolete and will die out sooner or later (even though they're still being used by sh*tty tutorials). Choose one of the
contemporary database extensions. In your case you can either use PDO or the MySQLi extension.
This is how you'd rewrite the product query using the PDO interface:
PHP Code:
<?php
// connect to database (put this in a separate file)
$connection_parameters = 'mysql:host=127.0.0.1;dbname=your_db';
$user = 'your_user';
$password = 'your_password';
try {
$database = new PDO($connection_parameters, $user, $password);
} catch (PDOException $e) {
die('Could not connect to database');
}
// create prepared statement for query (with ":id" being a parameter)
$product_statement = $database->prepare('
SELECT
product
FROM
product
WHERE
id = :id
');
// pass value to :id parameter and execute statement
$product_statement->execute(array(
'id' => $id
));
// fetch rows
while ($product_row = $product_statement->fetch()) {
...
}
There are some other issues, but I guess you wanna read the stuff above first.