PDA

View Full Version : whats up with this?



Scaper
02-12-2010, 01:36 AM
I keep getting this when i try and execute it in wamp

Parse error: parse error in C:\wamp\www\db\index.php on line 47



<?php
//start the session so you would stay logged in
//always must be on top
session_start();
//include config.php file
include('config.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>The site</title>
</head>
<body>
<center><a href="?p=idx">Home</a> - <a href="?p=page">Protected page</a>
<?php
$p=$_GET['p'];
//see my ?id= browsing tutorial
switch($p){
default:
//if user isn't logged in lets show him the log in form
if(!isset($_SESSION['username'])){
?>
<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input name="login" type="submit" value="Submit"><br>
Not <a href="register.php">registered</a>?
</form>
<?}
else{
//$_SESSION['username'] = the current users
//username. It will be echoed like "Hi, user!"
echo "<br><br>Hi, ".$_SESSION['username']."!";
echo "<a href='logout.php'>Log out</a>";}
break;
case 'page':
//you can use it like this or use include()
if(!isset($_SESSION['username'])){
echo '<br><br>Log in to see this page!';}else{
echo '<br><br>Only user who is logged in can see this!..and you see this so this means you are logged in;]';
}
}
</center>
</body>
</html>
?>

Nadeem
02-13-2010, 02:30 AM
...you have html inside a php block (44-46)... ;)


~NS

Scaper
02-15-2010, 06:48 PM
ahh i see thanks :)

void_hatred
02-15-2010, 11:31 PM
do you know that HTML is designed for the structure of web pages? they mark up what certain things are, for example a paragraph, list item

it's recommended not to use presentational elements such as center as they have no semantic meaning, yet better to use CSS

oh and the use of br is dis-recommended as well

(thanks to Craig` for some of the more technological words via MSN)

void_hatred

senrath
02-15-2010, 11:43 PM
oh and the use of br is dis-recommended as well

I'm curious as to what you'd use instead of br in this situation, if that's part of your advice.

Throwing in a separate block with CSS used for padding seems overkill in this situation.

void_hatred
02-15-2010, 11:59 PM
well first and foremost, I would like to make a point that it's not all about frequency (mimimal markup, but markup of which is most semantic (which describes it's content best))



<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input name="login" type="submit" value="Submit"><br>
Not <a href="register.php">registered</a>?
</form>


here, some may argue that a definition list is semantic (the label describes the input), whilst others would use an unordered list (a list of questions; though not in any particular order)

let's go for option b) using an unordered list:



<form action="login.php" method="post">
<fieldset>
<legend>Login</legend>

<ul>
<li>
<label for="username">Username:</label>
<input id="username" name="username" type="text">
</li>

<li>
<label for="password">Password:</label>
<input id="password" name="password" type="text">
</li>
</ul>

<input name="login" type="submit" value="Submit">
Not <a href="register.php">registered</a>?
</fieldset>
</form>


then some CSS like..



form ul {
list-style: none;
}

input[type="submit"] {
display: block;
}


...and as for



echo "<br><br>Hi, ".$_SESSION['username']."!";
echo "<a href='logout.php'>Log out</a>";


I'd do..



echo "<p>Hi," . $_SESSION["username"] . "!";
echo "<a href=\"logout.php\">Log out</a>";


and then maybe style it a bit, for example..



a[href="logout.php"]:before {
color: #000;
content: " | ";
font-weight: 800;
}


Note:
I do know that my examples are longer, in fact quite a bit longer, but as I mentioned in the first post it's semantics that count; not quantity, I know that a few, if not all will disagree of how I approach things, but.. that's me for you.

Once again, I'd like to thank Craig` for some help over MSN

void_hatred

Nadeem
02-16-2010, 05:00 AM
I'm curious as to what you'd use instead of br in this situation, if that's part of your advice.

Throwing in a separate block with CSS used for padding seems overkill in this situation.

http://www.hotdesign.com/seybold/21bedandbreakfast.html

You can go through the seybold seminars, they have some pretty interesting and neat stuff :)

btw, void_hatred, try not to over complicate simple tasks. Remember in web development, too much quantity can be harmful for a webpage since it creates more download time and more bandwidth usage, resulting in a slower web page. Make things as simple as you can get em to be ;)


~NS