PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
deadshot270
Forum Newbie
Posts: 3 Joined: Thu Jan 20, 2005 10:08 pm
Post
by deadshot270 » Thu Jan 20, 2005 10:17 pm
this is part of a account management page
the error i get is
Code: Select all
Parse error: syntax error, unexpected $end in C:\sites\dss_php_site\modules\your_account\index.php on
line 342
heres where i think the error is, the last line is line 339 and the rest of the code is closing up php, body, and html tags
Code: Select all
switch ( $op ) {
case "login":
login();
break;
case "logout":
logout();
break;
case "registration_form":
registration_form();
break;
case "registration_submit":
registration_submit();
break;
case "change_user_pass":
change_user_pass();
break;
case "change_info":
change_info();
break;
case "update_user_pass":
update_user_pass();
break;
case "update_info":
update_info();
break;
default:
manage();
}
Copyright 2004 DSS-Battalion
thanks, if u think the error is elsewhere in the script tell me and ill put the whole scrip on here
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 20, 2005 10:25 pm
time to post the rest of the script!
deadshot270
Forum Newbie
Posts: 3 Joined: Thu Jan 20, 2005 10:08 pm
Post
by deadshot270 » Thu Jan 20, 2005 10:27 pm
here it is if u dare
Code: Select all
<?php
if (eregi("index.php",$_SERVERї'PHP_SELF'])) {
Header("Location: modules.php");
die();
}
?>
<html>
<head>
<title>DeadShotSnipers Battalion</title>
</head>
<body>
<?php
function login() {
$sql_1 = "SELECT user, pass FROM members WHERE user=md5($_POSTїuser]) and pass=md5($_POSTїpass])";
$sql_2 = "mysql_query(".$sql_1.")";
if (mysql_num_rows($sql_login_2) == 1) {
session_start();
$_SESSIONїuser] = $_POSTїuser];
$_SESSIONїpass] = md5($_POSTїpass]);
$_SESSIONїlogged] = "logged";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account&op=manage"></head><body>";
echo "Thank you for logging in. You are being redirected to Your_Account page.";
} else {
echo "The Username and Password you have enter do not match.";
}
}
function logout() {
session_destroy();
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php"></head><body>";
}
function register_form() {
?>
<form action="modules.php?module=your_account&op=register" method="POST">
Username: <input type="text" maxlength="20" name="user">
<br><br>
Password: <input type="password" name="new_pass">
<br><br>
Confirm
<br>
Password: <input type="password" name="conf_new_pass">
<br><br>
Registration Code
<br>
(given to you by an officer): <input type="password" name="registration_code">
<br><br>
Name: <input type="text" name="name">
<br><br>
Age: <input type="text" name="age" maxlength="3">
<br><br>
Email: <input type="text" name="email">
<br><br>
Games:
<select type="menu" name="games" multiple>
<option value="America's Army">America's Army</option>
<option value="Medal fo Honor: Allied Assault">Medal fo Honor: Allied Assault</option>
</select>
<br><br>
Internet
<br>
Connection:
<select type="pulldown" name="inet_conn">
<option value="DIALUP">DIAL-UP</option>
<option value="DSL">DSL</option>
<option value="CABLE">CABLE</option>
<option value="T1">T1</option>
<option value="T3">T3</option>
</select>
<br><br>
Favorite
<br>
Maps:
<select type="menu" name="maps" multiple>
<option value="bridge_crossing">Bridge Crossing</option>
<option value="hq_raid">Headquarters Raid</option>
<option value="mout_mckenna">MOUT McKenna</option>
<option value="collapsed_tunnel">Collapsed Tunnel</option>
<option value="pipeline">Pipeline</option>
<option value="insurgent_camp">Insurgent Camp</option>
<option value="fls_assault">FLS Assault</option>
<option value="mountain_pass">Mountain Pass</option>
<option value="mountain_ambush">Mountain Ambush</option>
<option value="swamp_raid">Swamp Raid</option>
<option value="jrtc_farm_raid">JRTC Farm Raid</option>
<option value="weapons_cache">Weapons Cache</option>
<option value="river_basin">River Basin</option>
<option value="weapons_cache_se">Weapons Cache SE</option>
<option value="radio_tower">Radio Tower</option>
<option value="bridge_se">Bridge SE</option>
<option value="mountain_pass_se">Mountain Pass SE</option>
<option value="pipeline_sf">Pipeline SF</option>
<option value="sf_csar">SF CSAR</option>
<option value="sf_recon">SF Recon</option>
<option value="sf_hospital">SF Hospital</option>
<option value="sf_sandstorm">SF SandStorm</option>
<option value="sf_arctic">SF Arctic</option>
<option value="sf_village">SF Village</option>
</select>
<br><br>
Favorite
<br>
Weapons:
<select type="menu" size="8" name="_GUNS" multiple>
<option value="m16a2">M16A2</option>
<option value="m249">M249 "SAW"</option>
<option value="m203">M203</option>
<option value="m4a1">M4A1</option>
<option value="sf_m4">SOPMOD M4 "SF"</option>
<option value="m24">M24</option>
<option value="m82">M82 "Barret"</option>
<option value="spr">Special Forces Rifle "SPR"</option>
</select>
<br><br>
Please tell us of any special skills on the computer or otherwise that you have that you could contribute to help us.:
<br>
<textarea name="skills" cols="50" rows="8"></textarea>
<br><br>
<input type="submit" name="submit" value="SUBMIT">
</form>
<?php
}
function register_submit() {
if ($_POSTїregistration_code] == $registration_password) {
if ($_POSTїpass] == $_POSTїconf_pass]) {
$sql1 = "INSERT INTO members (user, password, name, age, email, inet_conn, maps, weapons, skills) values ($_POSTїuser], md5($_POSTїpass]), $_POSTїname],$_POSTїage], $_POSTїemail], $_POSTїinet_con], $_POSTїmaps], $_POSTїweapons], $_POSTїskills])";
mysql_query($sql1);
echo "Thank you for electing to become a member of the DeadShotSnipers Battalion. Our recruiting administrator will be contacting you within a few days.\n\nYour are being redirected back to our home page.";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php"></head><body>";
} else {
echo "The password you entered do not match.";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account&op=chage_user_pass"></head><body>";
}
} else {
echo "The registration code you have entered is invalid.\n\nYou are being redirected back to the registration page.";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account&op=registration"></head><body>";
}
function manage() {
if ($_SESSIONїlogged] == "logged") {
?>
<a href="modules.php?module=your_account&op=change_user_pass" target="_self">Change your Username and Password.</a>
<br>
<a href="modules.php?module=your_account&op=change_email" target="_self">Change your email address.</a>
<br>
<a href="modules.php?module=your_account&op=change_info" target="_self">Change your user information here.</a>
<?php
} else {
echo "You must login before you can manage your account.";
include("blocks/login_block.php");
}
}
function change_user_pass() {
if ($_SESSIONїlogged] == "logged") {
$sql_1 = "SELECT user FROM members WHERE user=$_SESSIONїuser]";
$sql_2 = mysql_result($sql_1); ?>
<form action="modules.php?module=your_account&op=update_user_pass" method="POST">
Username: <?php echo "<input type="text" maxlength="20" name="user" value="$sql_2">"; ?>
<br><br>
Old Password: <input type="password" name="old_pass">
<br><br>
New Password: <input type="password" name="new_pass">
<br><br>
Confirm New
<br>
Password: <input type="password" name="conf_new_pass">
<br><br>
<input type="submit" name="submit" value="SUBMIT">
<?php
} else {
echo "You must login before you can manage your account.";
include("blocks/login_block.php");
}
}
function change_info() {
if ($_SESSIONїlogged] =="logged") {
$sql_1 = "SELECT * FROM members WHERE user=$_SESSIONїuser]";
$sql_2 = mysql_fetch_array($sql_1);
$email = $sql_2їemail];
$age = $sql_2їage];
$inet_conn = $sql_2їinet_conn];
$maps = $sql_2їmaps];
$weapons = $sql_2їweapons];
$name = $sql_2їname];
$skills = $sql_2їskills];
?>
<form action="modules.php?modules=your_account&op=udate_info" method="POST">
Name: <input type="text" name="name" value=<?php echo ""$name""; ?>>
<br><br>
Age: <input type="text" name="age" maxlength="3" value=<?php echo ""$age""; ?>>
<br><br>
Email: <?php echo "<input type="text" name="email" value="$email">"; ?>
<br><br>
Games:
<select type="menu" name="games" multiple>
<option value="America's Army">America's Army</option>
<option value="Medal fo Honor: Allied Assault">Medal fo Honor: Allied Assault</option>
</select>
<br><br>
Internet
<br>
Connection:
<select type="pulldown" name="inet_conn">
<option value="DIALUP">DIAL-UP</option>
<option value="DSL">DSL</option>
<option value="CABLE">CABLE</option>
<option value="T1">T1</option>
<option value="T3">T3</option>
</select>
<br><br>
Favorite
<br>
Maps:
<select type="menu" name="maps" multiple>
<option value="bridge_crossing">Bridge Crossing</option>
<option value="hq_raid">Headquarters Raid</option>
<option value="mout_mckenna">MOUT McKenna</option>
<option value="collapsed_tunnel">Collapsed Tunnel</option>
<option value="pipeline">Pipeline</option>
<option value="insurgent_camp">Insurgent Camp</option>
<option value="fls_assault">FLS Assault</option>
<option value="mountain_pass">Mountain Pass</option>
<option value="mountain_ambush">Mountain Ambush</option>
<option value="swamp_raid">Swamp Raid</option>
<option value="jrtc_farm_raid">JRTC Farm Raid</option>
<option value="weapons_cache">Weapons Cache</option>
<option value="river_basin">River Basin</option>
<option value="weapons_cache_se">Weapons Cache SE</option>
<option value="radio_tower">Radio Tower</option>
<option value="bridge_se">Bridge SE</option>
<option value="mountain_pass_se">Mountain Pass SE</option>
<option value="pipeline_sf">Pipeline SF</option>
<option value="sf_csar">SF CSAR</option>
<option value="sf_recon">SF Recon</option>
<option value="sf_hospital">SF Hospital</option>
<option value="sf_sandstorm">SF SandStorm</option>
<option value="sf_arctic">SF Arctic</option>
<option value="sf_village">SF Village</option>
</select>
<br><br>
Favorite
<br>
Weapons:
<select type="menu" size="8" name="_GUNS" multiple>
<option value="m16a2">M16A2</option>
<option value="m249">M249 "SAW"</option>
<option value="m203">M203</option>
<option value="m4a1">M4A1</option>
<option value="sf_m4">SOPMOD M4 "SF"</option>
<option value="m24">M24</option>
<option value="m82">M82 "Barret"</option>
<option value="spr">Special Forces Rifle "SPR"</option>
</select>
<br><br>
Please tell us of any special skills on the computer or otherwise that you have that you could contribute to help us.:
<br>
<textarea name="skills" cols="50" rows="8"><?php echo "$skills"; ?></textarea>
<br><br>
<input type="submit" name="submit" value="SUBMIT">
<?php
} else {
echo "You must login before you can manage your account.";
include("blocks/login_block.php");
}
}
function update_user_pass() {
if ($_SEESIONїlogged] == "logged") {
if ($_POSTїnew_pass] == $_POSTїconf_new_pass] && $_POSTїold_pass] == $_SESSIONїpass]) {
$sql_1 = "REPLACE INTO members (user, pass) values ($_POSTїuser], md5($_POSTїpass])) WHERE user=$_SESSIONїuser] and pass=$_SESSIONїpass]";
if (mysql_query($sql_1)) {
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account"></head><body>";
echo "Your password has been changed.";
$_SESSIONїuser] = $_POSTїuser];
$_SESSIONїpass] = $_POSTїpass];
} else {
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account&op=chage_user_pass"></head><body>";
echo "The old password you entered does not match with the username.";
}
} elseif ($_POSTїpass] != $_POSTїconf] or $_POSTїold_pass] != $_SESSIONїpass]) {
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account&op=chage_user_pass"></head><body>";
echo "The new passwords you entered do not match. Please Try again.";
} else {
echo "This action could not be performed at this time";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php"></head><body>";
}
} else {
echo "You must login before you can manage your account.";
include("blocks/login_block.php");
}
}
function update_info() {
if ($_SESSIONїlogged] == "logged") {
$sql1 = "REPLACE INTO members (name, age, email, inet_conn, maps, weapons, skills) values ($_POSTїname],$_POSTїage], $_POSTїemail], $_POSTїinet_con], $_POSTїmaps], $_POSTїweapons], $_POSTїskills]) WHERE user=$_SESSIONїuser] and pass=$_SESSIONїpass]";
if (mysql_query($sql1)) {
echo "Our records have been updated.\n Thank you.";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php?module=your_account"></head><body>";
} else {
echo "This action could not be performed at this time";
echo "</body><head><meta http-equiv="refresh" content="2;URL=modules.php"></head><body>";
}
} else {
echo "You must login before you can manage your account.";
include("blocks/login_block.php");
}
}
switch ( $op ) {
case "login":
login();
break;
case "logout":
logout();
break;
case "registration_form":
registration_form();
break;
case "registration_submit":
registration_submit();
break;
case "change_user_pass":
change_user_pass();
break;
case "change_info":
change_info();
break;
case "update_user_pass":
update_user_pass();
break;
case "update_info":
update_info();
break;
default:
manage();
}
?>
</body>
</html>
harsha
Forum Contributor
Posts: 103 Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India
Post
by harsha » Thu Jan 20, 2005 11:13 pm
the
default
should follow a break; other wise switch case goes in to a loop
I think that is the problem
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 20, 2005 11:41 pm
function register_submit() wasn't closed.
dreamline
Forum Contributor
Posts: 158 Joined: Fri May 28, 2004 2:37 am
Post
by dreamline » Fri Jan 21, 2005 11:40 am
Yep and that's exactly why i code my if elses like this:
Code: Select all
if ()
{
}
else
{
if ()
{
}
}
I'm going for readability
And it's also easier for others to read, however that depends on the user though.. heheh
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Fri Jan 21, 2005 1:20 pm
dreamline, I also use that form of bracing, and for the same reason, but it turns out we are in the minority. Something like 80% use the form that harsha does. There was a poll on that in the General Discussion forum some time ago.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Fri Jan 21, 2005 1:25 pm
i believe the
if (..) {
} else {
}
was invented for saving space in a book on C.
With a decent editor you can easily transform the code to whatever style you prefer. And usually that editor will be able to close those brackets for you, remind you when a bracket is missing, etc.....
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 21, 2005 1:52 pm
it's actually from the days where you had a very limited amount of text on a screen, specifically lines. Waaaaay back in the stone-age of computing.
dreamline
Forum Contributor
Posts: 158 Joined: Fri May 28, 2004 2:37 am
Post
by dreamline » Fri Jan 21, 2005 1:59 pm
LOL, yea i remember those stone ages.. I even remember 8 bit ruling.. heheheh.. But if you have co-workers to work with and show your scripts then it's the way to go to brace them good so others can see easily what you are doing.. Or at least so i'm told.. heheh.. But i also believe i like it just better for me so i can read it more easily and trust me i have lotsa errors so it's easy for me to spot where the error is...