Forum Moderators: coopster

Message Too Old, No Replies

Authentication --Need help with parse erro

Parse error

         

djtwo

5:41 pm on May 3, 2006 (gmt 0)

10+ Year Member



Hey Guys, I have copied this code from a manual and edited the changes for my database. and keep getting

"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!

jatar_k

6:40 pm on May 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



welcome to WebmasterWorld djtwo,

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");
}

djtwo

8:23 pm on May 3, 2006 (gmt 0)

10+ Year Member



Thanks Jatar, it definitely has alot of misused and wrong quotes and single quotes and the SELECT STATEMENT. I went ahead and edited the rest of the program and changed those weired quotes.

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!

jatar_k

9:51 pm on May 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you're quite welcome

djtwo

10:20 pm on May 3, 2006 (gmt 0)

10+ Year Member



Hi Again,
Alright, so far I have made great progress, the page displays and all works well with the verification of the data, however once the customer clicks submit (with the necessary info entered), I get the following which is where I send the info to the database and send a copy of the info the the customer, I than Welcome them redirect them to the Members Only area:

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');
}
?>

------------------------------------

jatar_k

10:28 pm on May 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that may just be the curly quotes again

try it this way, you don't need the quotes aroung the variables at all

$mailsend=mail($email,$subj,$emess,$ehead);

djtwo

10:31 pm on May 3, 2006 (gmt 0)

10+ Year Member



Hahaha, I was looking right at it, and didn't catch it until I went to my text editor that displayed them (curls) a bit more obviously...Thanks! I'll let you know if I have any further problems. Have a good one!

djtwo

11:03 pm on May 3, 2006 (gmt 0)

10+ Year Member



Alright, I'm back again...This is a different page, but it flows along (or connects to) the User Sign Up or Login.

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>

jatar_k

11:20 pm on May 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't see a mysql_connect or a mysql_select_db

both of these are required before you can issue queries to mysql using mysql_query

djtwo

11:45 pm on May 3, 2006 (gmt 0)

10+ Year Member



Thanks Jatar, now I see what I did wrong, I used "include('library/config.php');" twice and didn't use my opendb.php.

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.

jatar_k

12:18 am on May 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



extract($row);

that's kind of a bad way to do it but...

it should actually work as $row should be an array. hmmm, are you sure that query is working? If $row isn't an array then it makes me think that it isn't returning the proper values from mysql_fetch_array

djtwo

1:02 am on May 4, 2006 (gmt 0)

10+ Year Member



Hi Jatar,
what way would you recommend and how would I go about it? Would the changes affect anything major? I am a begginer and got the code from a book (ebook) as I mentioned earlier so I do not really know 100% what is meant by the whole array thing.

Thanks for your time and effort. In case your off to wonderland, have a good night, if not, thanks for the help.

jatar_k

1:10 am on May 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



west coast here so I am wanderin around for a bit yet, well, until hockey is on that is, I am Canadian after all ;)

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.

djtwo

1:44 am on May 4, 2006 (gmt 0)

10+ Year Member



Hey Jatar, I hope hockey is still on! I have not been able to fix the error.

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!

jatar_k

2:14 am on May 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



thats the error then

it can't select anything which is why in that last script extract tells you it isn't an array

go back to your insert statement and figure out why it isn't working then worry about the rest after

djtwo

2:18 am on May 4, 2006 (gmt 0)

10+ Year Member



Sounds like a plan, I'll get back if I continue with any problems. Thanks for all the help Jatar, I very much appreicate it. Until next time, have a good and safe one.

-Djtwo