Forum Moderators: coopster
"Parse error: parse error, unexpected T_STRING in /hsphere/local/home/sample/website.com/database2/Login.php on line 15
"
NOTE: The code uses a switch statement that allows the customer to either "Login" or create "New" account.
There is more to the code but I thought that should be enough to solve the issue. Thanks for any help.
--Djtwo
The code is as follows:
--------------------------
<?php
/* Program: Login.php
* Desc: Login program for the Members Only section of the
* pet store. It provides two options: (1) login
* using an existing Login Name and (2) enter a new
* login name. Login Names and passwords are stored
* in a MySQL database.
*/
session_start(); # 9
include(“library/coninfo.php”); #10
switch (@$_GET[‘do’]) #11
{
case “login”: #13
$connection = mysql_connect($host, $user,$password) #14
or die (“Couldnt connect to server.”); #15
$db = mysql_select_db($database, $connection)
or die (“Couldn’t select database.”); #17
$sql = “SELECT loginName FROM Member
WHERE loginName=’$_POST[fusername]’”; #20
$result = mysql_query($sql)
or die(“Couldn’t execute query.”); #22
$num = mysql_num_rows($result); #23
if ($num == 1) // login name was found #24
{
$sql = “SELECT loginName FROM Member
WHERE loginName=’$_POST[fusername]’
AND password=password(‘$_POST[fpassword]’)”;
$result2 = mysql_query($sql)
or die(“Couldn’t execute query 2.”); #30
$num2 = mysql_num_rows($result2);
if ($num2 > 0) // password is correct #32
{
$_SESSION[‘auth’]=”yes”; #34
$logname=$_POST[‘fusername’];
$_SESSION[‘logname’] = $logname; #36
$today = date(“Y-m-d h:m:s”); #37
$sql = “INSERT INTO Login (loginName,loginTime)
VALUES (‘$logname’,’$today’)”;
mysql_query($sql) or die(“Can’t execute query.”);
header(“Location: Member_page.php”); #41
}
-------------------------------------------
There is more to the code but I thought that should be enough to solve the issue. Thanks!
is it broken onto seperate lines like you posted? it may just be a weird formatting thing that is causing the parse error. All those curly quotes are weird too. There also seem to be ticks where there should be single quotes.
also your select login query wouldn't have worked as is, when you use array syntax it won't resolve inside double quotes, you need to concatenate it, so I changed that.
I just reformatted it, see if that makes any difference, I think I got them all
session_start();
include("library/coninfo.php");
switch (@$_GET['do']) {
case "login":
$connection = mysql_connect($host, $user,$password) or die ("Couldnt connect to server.");
$db = mysql_select_db($database, $connection) or die ("Couldn’t select database.");
$sql = "SELECT loginName FROM Member WHERE loginName=’$_POST[fusername]’";
$result = mysql_query($sql) or die("Couldn’t execute query.");
$num = mysql_num_rows($result);
if ($num == 1) { // login name was found
$sql = "SELECT loginName FROM Member WHERE loginName='" . $_POST[fusername] . "' AND password=password('" . $_POST[fpassword] . "')";
$result2 = mysql_query($sql) or die("Couldn’t execute query 2.");
$num2 = mysql_num_rows($result2);
if ($num2 > 0) { // password is correct
$_SESSION['auth']="yes";
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:m:s");
$sql = "INSERT INTO Login (loginName,loginTime) VALUES ('$logname','$today')";
mysql_query($sql) or die("Can’t execute query.");
header("Location: Member_page.php");
}
WOW amazing, I spent that last hour just fixing all those weird quotes. There was a bundle of them. Thanks Jatar...Although I am not yet 100% done, I'll probably open up another post if the topic is different. Thanks!
These are the errors:
Warning: mail() expects at least 3 parameters, 1 given in /hsphere/local/home/dayer/lbdrywall.com/database2/Login.php on line 152
Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/website.com/database2/Login.php:152) in /hsphere/local/home/website.com/database2/Login.php on line 153
"
LINE 152 IS NEAR THE END IN BOLD
The code is as follows, again I apologize for the length, this thread may need another page. Thanks!:
-----------------------------
/* check to see if login name already exists */
$connection = mysql_connect($host, $user,$password) or die ("Couldnt connect to server.");
$db = mysql_select_db($database, $connection) or die ("Couldn’t select database.");
$sql = "SELECT loginName FROM Member
WHERE loginName='$newname'";
$result = mysql_query($sql)
or die("Couldn’t execute query CHECK123.");
$num = mysql_numrows($result);
if ($num > 0)
{
unset($_GET['do']);
$message_new = "$newname already used. Select another
Member ID.";
include('login_form.php');
exit();
}
else
{
$today = date("Y-m-d");
$sql = "INSERT INTO Member (loginName,createDate,
password,firstName,lastName,street,city,
state,zip,phone,fax,email) VALUES
(‘$newname’,’$today’,password(‘$newpass’),
‘$firstName’, ‘$lastName’,’$street’,’$city’,
‘$state’,’$zip’,’$phone’,’$fax’,’$email’)";
mysql_query($sql);
$_SESSION['auth']="yes";
$_SESSION['logname'] = $newname;
/* send email to new member */
$emess = "A new Member Account has been setup. ";
$emess.= "Your new Member ID and password are: ";
$emess.= "\n\n\t$newname\n\t$newpass\n\n";
$emess.= "We appreciate your interest in Your Company";
$emess.= "at www.Sample.com. \n\n";
$emess.= "If you have any questions or problems,";
$emess.= "email CS@samplestore.com";
$ehead="From: newaccount@dclubi.com\r\n";
$subj = "Your new Member Account from Pet Store";
$mailsend=mail("$email”,”$subj”,”$emess”,”$ehead"); #152
header('Location: New_member.php');
}
break;
default:
include('login_form.php');
}
?>
------------------------------------
This page Welcomes the New Member once they have successfully made an account. It welcomes them by name [ $firstName $lastName ], tell them specific info, and gives them the options as to where to next.
The errors I got are:
"
Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /hsphere/local/home/dayer/lbdrywall.com/database2/New_member.php on line 18
Warning: mysql_query(): A link to the server could not be established in /hsphere/local/home/dayer/lbdrywall.com/database2/New_member.php on line 18
Couldn’t execute query 1.
"
The code is as follows, Again I apologize for length Thank you very much:
---------------------------------
<?php
/* Program: New_member.php
* Desc: Displays the new member welcome page. Greets
member by name and gives user choice to enter
* restricted section or go back to main page.
*/
session_start(); # 7
if (@$_SESSION['auth']!= "yes") # 9
{
header('Location: Login.php');
exit();
}
include('library/config.php'); #14
include('library/config.php');
$sql = "SELECT firstName,lastName FROM Member
WHERE loginName='{$_SESSION['logname']}'";
$result = mysql_query($sql) #18
or die("Couldn’t execute query 1.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
extract($row);
echo "<html>
<head><title>New Member Welcome</title></head>
<body>
<h2 align='center' style='margin-top: .7in'>
Welcome $firstName $lastName</h2>\n"; #29
?>
<p>Your new Member Account lets you enter the Members Only
section of our web site. You’ll find special discounts and
bargains, a huge database of animal facts and stories, advice
from experts, advance notification of new pets for sale,
a message board where you can talk to other Members, and much
more.
<p>Your new Member ID and password were emailed to you. Store
them carefully for future use.<br>
<div align="center">
<p style="margin-top: .5in"><b>Glad you could join us!</b>
<form action="Member_page.php" method="POST">
<input type="submit"
value="Enter the Members Only Section">
</form>
<form action="PetShopFrontMembers.php" method="POST">
<input type="submit" value="Go to Pet Store Main Page">
</form>
</div>
</body></html>
Ok, I'm almost finished, now I get
Warning: extract(): First argument should be an array in /hsphere/local/home/dayer/lbdrywall.com/database2/New_member.php on line 21
NOTE the error causes the user name not to be displayed when I Welcome them by name for the first time.
I get that error on the same program as the previous post. Thanks for the help! I greatly appreciate it.
Thanks for your time and effort. In case your off to wonderland, have a good night, if not, thanks for the help.
you can keep it like that for now but I just admit I haven't seen that before, just looks funny to me. I can't think of a reason it is wrong per se but it just doesn't seem quite right. Leave it as is unless you have a reason not to, no use coding more just cause I said.
Did you get that error fixed?
I still wonder whether the query is working at all, otherwise the extract should work.
One thing interesting to note is that when I went to check my database to see if the account info was added I found that nothing ever entered it. My tables are still empty. Do you think that might be a hint as to why I get the error?
I really don't have a clue why it isn't working, I copied and pasted it right from the book. The entire program for that page is on the past post. Any ideas?
Thanks for all the help!