After pulling my hair I am close to giving up. Ive stared at the code for hours but I just cant see whats wrong. I have searched the net for similar faults but...it just dont make any sense to the fault I have (or rather the row the fault is said to be on).

Im new to the PHP coding buy are fairly confident in both html and css. To get to know the PHP coding Im now taking a distancecourse (BAD MISTAKE - I have nobody to ask if something flops belly up!!) so its many trial and errors (you learn by that too but...much hairpulling).

Anyway - to my problem. Im trying to do a "simple" webshop "thing" and are following a tutorial in the book thats in this course. But it just wont work for me... I have phpMyAdmin 3.4.5, use XAMPP as local server and Crimson Editor as...well...my code editor.

The database is named "webshop" and have 3 tables(and have these "tables" in them); customer ( cid, fname, lname, adress, postno, city, phone, login, password ), orders (oid, cid, pid, quantity), products (pid, itemno , prodtitle, descr ). The files are named shop.php and newreg.php.

The error that I get when I try and test "shop.php" is "Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\project\shop.php on line 41". LINE 41 in shop.php is the following: "mysql_select_db("webshop");" (as you can see for yourself).
When I try and check if the "newreg.php" work I can at least see that but it dont insert anything in the database.

So...where the heck (pardon my "french") is the fault....its probably something tinyweeny thing but...I just cant get it to work.

Also...I would also, if possible, have some help with how to make a sort of "admin" thing so I can ADD, CHANGE and DELETE things in my shop (like a admin section) without using phpMyAdmin.

I know you guys probably get that question a million times over but...if you dont ask...Thank you a lot in advance!

shop.php

<?
session_register("cart");
?>

<html>
<head>
<title>Shop</title>
</head>
<body>

<?
if(isset($_POST['ok'])){
	Add();
}

if(isset($_POST['remove'])){
	Remove();
}

if(isset($_GET['action'])||isset($_POST['action'])){
	if($_GET['action']=='login'){
	LogIn();
}
	if($_POST['action']=='insert'){
	Insert();
}

}else{
	ShowProducts();
	ShowContent();
}

?>

</body>
</html>

<?
function ShowProducts() {
	$link = mysql_connect ("localhost", "root", "")
	mysql_select_db("webshop");
	$sql="SELECT * FROM products";
	$result = mysql_db_query("products", "$sql");
	echo "<table>";
	echo "<tr><th>Item<th><th>Quantity<th><th><th></tr>";
	while($row=mysql_fetch_array($result)){
		echo "form method='post' action='shop.php'">;
		echo "<tr><td>";
		echo $row["descr"];
		echo "<input type='hidden' name='descr' value='".$row["descr"]."'>";
		echo "</td><td><input type='text' name='quantity'></td>";
		echo "<td><input type='hidden' value='".$row['pid']."' name='id'>";
		echo "<input type='submit' value='Add to Cart' name='ok'></td></tr></form>";
	}
mysql_close ($link);
echo "</table>";
}
?>

function add() {
$quantity = $_POST['quantity'];
$id = $_POST['id'];
$descr = $_POST['descr'];

if(!empty($_POST['ok'])) {
	if(!SESSION['cart'][$_id]["id"])
	{
	$_SESSION['cart'][$id]["id"]=$id;
	$_SESSION['cart'][$id]["quantity"]=$quantity;
}else{
	$_SESSION['cart'][$id]["quantity"]=$_SESSION['cart'][$id]["quantity"]+$quantity;	
	}
}
}

function ShowContent() {
if(!empty($_SESSION['cart'])) {
	echo "<br/> You order contains the following:"<br/>;
	echo "<table>";
	echo "<tr><th>Item</th><th>Quantity</th><th></th></tr>";
		foreach($_SESSION['cart'] as $p){
			if(!$p["quantity"]==0){
				echo "<form method='post' action='shop.php'";
				echo "<tr><td>".$p["descr"]."</td><td>".$p["quantity"]."</td></td>";
				echo "<input type='hidden' value="'.$p["id"].'" name"id">;
				echo "input type='submit' value='Remove' name='remove'></tr>";
				echo "</form>";
			}
	}
echo "</table>";
echo "<a href='shop.php=action=login'">Go to CheckOut</a>";
	}				
}	

function remove()
	$id=$_POST['id']:
	$_SESSION['cart'][$id]["quantity"]=0:
}

function Login(){
	echo "Submit your login and password if you are a returning customer<br/>;
	echo "form method='post' action='shop.php'>";
	echo "Login:<br/><input type='text' name='login'><br/>";
	echo "Password:<br/><input type='password' name='password'><br/>";
		echo "input type='submit' name='auction' value='Send'>";
	echo "<a href='newreg.php'>New Customer? Sign up here!</a>"
	}

function Insert(){
	$login = $_POST['login'];
	$password = $_POST['password'];

$link = mysql_connect ("localhost", "root", '');
$sql="SELECT * FROM customer WHERE login='$login' AND password='$password'";
$result = mysql_db_query("products", "$sql");
	if(!($row=mysql_fetch_array($result))){
		echo "Wrong Login";
		echo "Please try again!";
	LogIn();
]
else {
	$cid = $row['cid'];
	$link = mysql_connect ("localhost", "root", '');
	foreach($_SESSION['cart'] as $p){
		if(!$p["quantity"]==0){
			$pid = $p["id"];
			$quantity = $p{"quantity"];
			$sql=INSERT INTO orders(cid, pid,quantity) VALUES ($cid,$pid,$quantity)";
			my_sql_query("products", "$sql");
		}
	}
session_unset();
echo "Thank you for your order<br/> Welcome back<br/>";	
echo "<a href="shop.php">Back to the store</a>";
mysql_close($link);
}

</body></html>

newreg.php

<? 
if(isset($_POST['check'])) {
	Check();
}
else {
Showform();
}

function Showform() {
?>
<table>
<form action="newreg.php" method="post" name='reg' OnSubmit="return send_OnClick();">
<tr><td>Firstname: </td><td><input type="text" name="fname"></td></tr>
<tr><td>Lastname:</td><td> <input type="text" name="lname"></td></tr>
<tr><td>Adress: </td><td><input type="text" name="adress"></td></tr>
<tr><td>Postno: </td><td><input type="text" name="postno"></td></tr>
<tr><td>City: </td><td><input type="text" name="city"></td></tr>
<tr><td>Phone: </td><td><input type="text" name="phone"></td></tr>
<tr><td>Login: </td><td><input type="text" name="login"></td></tr>
<tr><td>Password: </td><td><input type="password" name="password"></td></tr>
<tr><td></td><td><input type='reset' value='Reset'>
<input type='submit' name='send' value='Send'></td></tr>
</form>
</table>
<? 
}

function Check() {
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$adress=$_POST['adress'];
$postno=$_POST['postno'];
$city=$_POST['city'];
$phone=$_POST['phone'];
$login=$_POST['login'];
$password=$_POST['password'];

$link = mysql_connect ("localhost", "root","");
$sql="SELECT * FROM customer WHERE login='$login' AND password='$password'";
$result = mysql_db_query("products","$sql");

if(!($row=mysql_fetch_array($result))) {
$sql="INSERT INTO customer(fname,lname,adress,postno,city,phone,login,password)";
$sql=$sql."VALUES('$fname','$lname','$adress','$postno','$city','$phone','$login','$password')";
mysql_db_query("products","$sql");
echo "Congrats - You are now registrered as client.<br>";
echo "<a href='shop.php?action=login'>Back</a>";
	}
else {
echo "Sorry, your username was taken, please use another.";
Showform();
}
mysql_close ($link);
}
?>

<script language="JavaScript">
function send_OnClick() {
	var los = document.reg.password.value;
	var log = document.reg.login.value;

if((los.length != 0) && (log.length != 0)) {
	return true;
} else {
	alert("You must login to be able to shop");
	return false;
}
}
</script>

    First, welcome to PHPBuilder!

    Second, note that there is a stickied thread dedicated to Parse error issues in the General Help forum entitled: Parse Error: syntax error. Please refer to that thread in the future when posting about parse errors (and you might want to search through it first - there are only a few different types of solutions that cover about 90&#37; of all parse errors!).

    Also note that you don't need to post every bit of code you have when the error message clearly references a single line in a single file; instead, start with that line (and a few statements above it, so we can start to see the context) as we can always ask to see more. πŸ˜‰

    Finally, your problem is caused by a missing semicolon on the line preceding the one referenced in the error message.

      Thank you... Sorry for my "bo-bo's"... I didnt check the General help first since..well...I am a newbie and therefore it seemed more logical to start here..

      Reason why I posted the whole "shebang" was that Ive seen in other forums people got annoyed bc newbies often dont post "enough" info when they want help... guess there is a "too much info" too πŸ˜‰

      Thanks again...altho I got other errors now but I gonna check the thread you adviced me too....

      sigh...who needs hair on their head anyway :/:queasy::glare:

        decor;10993673 wrote:

        I didnt check the General help first since..well...I am a newbie and therefore it seemed more logical to start here..

        Excellent point - I added a sticky to this forum to inform new members of that thread's existence.

        decor;10993673 wrote:

        Ive seen in other forums people got annoyed bc newbies often dont post "enough" info when they want help... guess there is a "too much info" too πŸ˜‰

        Excellent points again (the both of them, unfortunately). Just know that all too often (and I'm fully admitting my own guilt here, too), many people glancing through new threads throughout the board often make some initial judgments about the complexity of the problem simply based upon the amount of information contained in the first post.

        (Or is that just me?)

          ok...adding that cause these:
          [INDENT]----------
          Deprecated: Function session_register() is deprecated in C:\xampp\htdocs\project\shop.php on line 2

          Deprecated: Function mysql_db_query() is deprecated in C:\xampp\htdocs\project\shop.php on line 43

          Deprecated: mysql_db_query() [function.mysql-db-query]: This function is deprecated; use mysql_query() instead in C:\xampp\htdocs\project\shop.php on line 43
          Item Quantity

          Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\project\shop.php on line 46

          Fatal error: Call to undefined function ShowContent() in C:\xampp\htdocs\project\shop.php on line 30

          --------
          [/INDENT]
          I just dont really know where to start....been staring at this all day and just....dont see anything....sigh..

          What does "deprecated" mean? Something is missing I guess. (English isnt my native tongue)

          Thank you in advance....

            decor;10993681 wrote:

            What does "deprecated" mean? Something is missing I guess.

            Not at all; I believe the Wikipedia page on Deprecation says it best:

            Wikipedia wrote:

            In the process of authoring computer software, its standards or documentation, or other technical standards, deprecation is a status applied to features, characteristics, or practices to indicate that they should be avoided, typically because they have been superseded. (Emphasis added)

            For more specific answers:

            decor;10993681 wrote:

            Deprecated: Function session_register() is deprecated

            Rather than using [man]session_register/man to add variables to a session, use the $_SESSION superglobal array instead. More info on that array can be found here: [man]reserved.variables.session[/man].

            decor;10993681 wrote:

            Deprecated: Function mysql_db_query() is deprecated

            Deprecated: mysql_db_query() [function.mysql-db-query]: This function is deprecated; use mysql_query() instead

            You should use [man]mysql_select_db/man to first select a database and subsequently execute queries against it using [man]mysql_query/man. This function simply combined the two actions into one (even though the former only needs to be done once).

            Then again, note that the entire [man]mysql[/man] extension has been superseded by the improved extension [man]MySQLi[/man]; new projects should use that extension (or others, such as [man]PDO[/man]).

            decor;10993681 wrote:

            Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

            See the link in my signature for an in-depth discussion of this error message: MySQL(i) PHP warning

            decor;10993681 wrote:

            Fatal error: Call to undefined function ShowContent()

            'ShowContent' isn't the name of any built-in PHP function or any extension that I'm aware of, so either you forgot to include a file that defines this function or you've mistyped the name of the function you intended to call.

              Ugh,,,I feel so stupid,,,oh well...I will ponder on HOW to do with your advices (why cant stuff just work :/) and try and fix this tomorrow ...I feel fried...just hope it will make more sense tomorrow.

              Dont help that the stupid book is a old one too...why cant a university try and keep up and use "todays books" with their courses....

              Thanks again...

                For the undefined function error, note that the syntax highlighting in shop.php stops after the ShowProducts() function definition; you escape out of PHP code just after that function definition despite the fact that there is more PHP code following it.

                  7 days later

                  We were all where you are at some point. No worriesπŸ™‚
                  Btw, if you are on a *nix system you can do a php -f filename.php and it will parse it for you finding syntax errors. If you already know this then ignore meπŸ™‚

                    hsnopi;10994072 wrote:

                    Btw, if you are on a nix system you can do a php -f filename.php and it will parse it for you finding syntax errors.

                    That would be a "-l" (the letter L, as in Lint Check). Also, that option is available on any OS that PHP can be compiled on - not just the nix variants.

                      bradgrafelman;10994074 wrote:

                      That would be a "-l" (the letter L, as in Lint Check). Also, that option is available on any OS that PHP can be compiled on - not just the *nix variants.

                      Just verified this works on windows (with the -l (L) option as bg suggested). Always something new to learn on this board =D

                        Write a Reply...