Link to home
Start Free TrialLog in
Avatar of KevPerkins
KevPerkins

asked on

PHP Membership System

I have just completed a tutorial on Creating a membership system. I have adapted the input form and the field variables to use on one of my new projects - creating a membership area on a web site for Medical professionals

my first error I get is:

Parse error: parse error, unexpected T_VARIABLE in
/home/breforml/public_html/Mediproregister_checker.php on line 22

my line 22 is simple and reads:
$medifName = stripslashes ($medifName);

Please help.

Thanks

Kev
Avatar of Diablo84
Diablo84

The error is on the line before it

look for a missing semi colon at the end of the line, or a possible missing double/single quote

there is also the possibility of a missing closing curly (or round) bracket but its more likely the semi colon
in case you could not find the problem, post the code from line 18 till 25.
Avatar of KevPerkins

ASKER

Thanks, just checked the code and you're spot on - it was a missing semi colon.
Another error has cropped up:

Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';'
in /home/breforml/public_html/Mediproregister_checker.php on line 71

lines 70 to 73 currently look like this:
70: if ($username_check > 0) {
71:  echo "<strong><font size="2" face="Arial, Helvetica, sans-serif">The username
you have entered has already been chosen by another member on our
database. Please choose a different username and resubmit you registration.</font></strong><font size="2" face="Arial, Helvetica, sans-serif"><br>
";
72: unset ($medi_username);
73: }

Sorry to be a pain but please could you help me here.

Thanks

Kev
71:  echo "<strong><font size="2" face="Arial, Helvetica, sans-serif">The username

Too much quotes. You have to escape the quotes of the attribute values.

And, if it's possible, please try to substitute <font> with CSS.
Make it as following:

70: if ($username_check > 0) {
71:  echo "<strong><font size='2' face='Arial, Helvetica, sans-serif'>The username
you have entered has already been chosen by another member on our
database. Please choose a different username and resubmit you registration.</font></strong><font size='2' face='Arial, Helvetica, sans-serif'><br>";
72: unset ($medi_username);
73: }

Its what dufduf said, but just showed you.
Thanks again
good luck with your membership system

|)iablo
I think you forgot to *split* the points.
:-)
Hi Guys

I seem to have been successful in debugging all the code right up until the last line. I now get an error which says:

Parse error: parse error, unexpected $ in /home/breforml/public_html/Mediproregister_checker.php on line 145

However, the last line has no $ in it at all....

137: mail ($medi_Email, $subject, $message,
138: "From: Breform.com Webmaster <webmaster@breform.com>\n
139: X-mailer: PHP/".phpversion());
140: echo 'Your membership information has been mailed to your email address which you supplied as $medi_Email.<br>
141: Please check it and follow the directions!';
142: }
143: ?>
144: </body>
145: </html>

What have I missed?


if you want the contents of the variable to display use double quotes in the echo line, ie:

echo "Your membership information has been mailed to your email address which you supplied as $medi_Email.<br>
Please check it and follow the directions!";

The parse error means at some point before the end of the script you have most likely missed another closing bracket or semi colon, besides the problem stated above there is nothing else wrong with the code you submitted.
OK I corrected the quotation marks but the error remains the same:

Parse error: parse error, unexpected $ in /home/breforml/public_html/Mediproregister_checker.php on line 145

Here is ALL the code:

1:<html>
2:<head>
3:<title>Breform Medical Member Registration Error Checker</title>
4:<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5:</head>
6:<body>
7:<?php
8:include 'dbcon.inc';
9:// define the post fields into simple variables
10:$medifName = $_POST['medifName'];
11:$medisName = $_POST['medisName'];
12:$mediTitle = $_POST['mediTitle'];
13:$medi_Email = $_POST['medi_Email'];
14:$medi_wTel = $_POST['medi_wTel'];
15:$medi_cTel = $_POST['medi_cTel'];
16:$medi_hTel = $_POST['medi_hTel'];
17:$medi_username = $_POST['medi_username'];
18:$pracNum = $_POST['pracNum'];
19:$discipline = $_POST['discipline'];
20:$comments = $_POST['comments'];
21:/* Let's strip some slashes in case the user entered any escaped characters.*/
22:$medifName = stripslashes ($medifName);
23:$medisName = stripslashes ($medisName);
24:$mediTitle = stripslashes ($mediTitle);
25:$medi_Email = stripslashes ($medi_Email);
26:$medi_username = stripslashes ($medi_username);
27:$discipline = stripslashes ($discipline);
28:
29:/* Do some error checking on the form posted fields */
30:if ((!$medifName) || (!$medisName) || (!$medi_Email) || (!$medi_cTel) || (!$medi_username) || (!$pracNum)) {
31:echo "You did not submit the following required information! <br />";
32:if (!$medifName) {
33:echo "Your first name is a required field. Please enter it below.<br />";
34:}
35:if (!$medisName) {
36:echo "Your surname is a required field. Please enter it below. <br />";
37:}
38:if (!$medi_Email) {
39:echo "Email address is a required field. Please enter it below. <br />";
40:}
41:if (!$medi_cTel) {
42:echo "Cell phone number is a required field. Please enter it below. <br />";
43:}
44:if (!$medi_username) {
45:echo "Please enter a username below. <br />";
46:}
47:if (!$pracNum) {
48:echo "Practice number is a required field. Please enter it below. <br />";
49:}
50:include 'mediproregister.php'; //show the form again!//
51:
52:// End the error checking and if everything is OK, we can move on to creating the user account.//
53:
54:exit(); //if the error checking has failed we can exit the script here.
55:}
56:
57://now we will do some error checking to make sure that the user's email address or username does not exist on the database already//
58:
59:$sql_email_check = mysql_query ("SELECT email address FROM users WHERE email_address = '$medi_Email'");
60:$sql_username_check = mysql_query ("SELECT username FROM users WHERE username = '$medi_username'");
61:$email_check = mysql_num_rows($sql_email_check);
62:$username_check = mysql_num_rows($sql_username_check);
63:
64:if (($email_check > 0) || ($username_check > 0)) {
65:echo "Please fix the following: <br>";
66:if ($email_check > 0) {
67:echo "<strong> The email address you have entered has already been used by another member in our database. Please submit a different email 68:address. </strong><br>
69:"; unset ($medi_Email);
70:}
71:if ($username_check > 0) {
72:echo "<strong><font size='2' face='Arial, Helvetica, sans-serif'>The username
73:you have entered has already been chosen by another member on our
74:database. Please choose a different username and resubmit you registration.</font></strong><font size='2' face='Arial, Helvetica, sans-serif'><br>
75:";
76:unset ($medi_username);
77:}
78:include 'mediproregister.php'; //show</font> form again//
79:exit (); //exit the script so that we do not create this account?? } //If everything has passed both error checks then it's time to create the account//
80:
81:// random password generator.
82:/* http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php 
83:we'll generate a random password for the user and encrypt it, email it and then enter it into the database.*/
84:
85:function makeRandomPassword() {
86:$salt = "abcdefghijklmnopqrstuvwxyz0123456789";
87:srand ((double) microtime()*1000000);
88:$i = 0;
89:while ($i<=7) {
90:$num = rand() % 33;
91:$tmp = substr($salt, $num, 1);
92:$pass = $pass.$tmp; $i ++;
93:}
94:return $pass;
95:}
96:$random_password = makeRandomPassword ();
97:$db_password = md5 ($random_password);
98:
99://enter info into the database.
100: $info = htmlspecialchars ($comments);
101: $sql = mysql_query ("INSERT INTO users (medifName, medisName, mediTitle,
102: medi_Email, medi_wTel, medi_hTel, medi_cTel medi_username, pracNum, discipline,
103: mediPassword, comments, signup_date) VALUES ('$medifName', '$medisName', '$mediTitle', '$medi_Email',
104: 'Smedi_wTel', '$medi_hTel', '$medi_cTel', '$medi_username', '$pracNum', '$discipline',
105: '$db_password', '$info', now())") or die (mysql_error());
106: if (!$sql) {
107: echo "<font size='2' face='Arial, Helvetica, sans-serif'>
108: There has been an error creating your account, please contact the webmaster at <a
109: href='mailto:webmaster@breform.com'>webmaster@breform.com</a></font>";
110: } else {
111: $userid = mysql_insert_id ();
112: //Now let's mail the user
113: $subject = "Your membership at Breform.com!";
114: $message = "Dear $mediTitle $medifName $medisName,<br>Thank you for registering at our website http://www.breform.com.<br>
115: You are two steps away from activating your account and being able to access our medical professionals' members' area.<br>
116: To activate your membership please click here:<br>
117: http://www.breform.com/activate.php?id=$userid&code=$db_password<br>
118: <br>
119: Once you activate your membership, you will be able to login with the following information:<br>
120: <br>
121: <table width='300' border='1' cellspacing='0' cellpadding='3'>
122:  <tr>
123:    <td width='101'>Username:</td>
124:    <td width='187'>$medi_username&nbsp;</td>
125:  </tr>
126:  <tr>
127:    <td>Password:</td>
128:    <td>$mediPassword</td>
129:  </tr>
130: </table>
131: <br>
132: Many Thanks<br>
133: <br>
134: The Webmaster
135: Breform (Pty) Ltd
136: THIS IS AN AUTOMATED RESPONSE, PLEASE DO NOT REPLY TO THE SENDER OF THIS MESSAGE!";
137 mail($medi_Email, $subject, $message,
138: "From: Breform.com Webmaster <webmaster@breform.com>\n
139: X-mailer: PHP/".phpversion());
140: echo "Your membership information has been mailed to your email address which you supplied as $medi_Email.<br>
141: Please check it and follow the directions!";
142: }
143: ?>
144: </body>
145: </html>

I have looked and re-looked but I still can't find the missing bracket.

I have just had a quick look and unless im mistaken this if statement does not have a closing bracket

if (($email_check > 0) || ($username_check > 0)) {

try adding } where it should end and i suspect that should do it
You have a } in line 79 which is enclosed inside comments. ( // )

Remve the comment line for }
ahh, that would be the missing one from the if statement :)
The form now goes a bit further but returns the following error on submitting:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/breforml/public_html/Mediproregister_checker.php on line 61

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/breforml/public_html/Mediproregister_checker.php on line 62

These lines of code look like this
61: $email_check = mysql_num_rows($sql_email_check);
62: $username_check = mysql_num_rows($sql_username_check);

Please advise.
mysql_num_rows() wants a result resource as a parameter. mysql_query() returns false, if the query didn't succeed. Check that before calling mysql_num_rows. Query might fail for several reasons. You don't seem to call mysql_connect() before querying. That's allowed, mysql_query will try to establish the connection, if you don't supply it with one. I suppose it fails there. I would establish the connection explicitly.
I thought my include in line 8 would suffice. Obviously not. In the original tutorial code they had a file called db.php which was always on the second line right after <?

I'll try this out and see if it changes anything.
OK, I have written a file as per the code recommended by the tutorial. The file is called db.php and here is the code:

<?php
$host = 'localhost';
$username = 'breforml_kevin';
$password = 'joshcam1';
$database = 'breforml_main';

$connection = mysql_pconnect($host, $username, $password);

$mysql_select_db($database, $connection);
?>

But now I've just landed myself with another error:

Fatal error: Call to undefined function: () in /home/breforml/public_html/db.php on line 1

What am I doing wrong here?
Ok, my code which works is:

    $server="localhost";
    $database="x";

    $username="x";
    $password="x";

    $connection = mysql_connect($server, $username, $password) or die("Could not connect to MySQL server");
    mysql_select_db($database, $connection) or die("Could not select database $database: ".mysql_error($connection));

the only difference is that you're using a persistent conneciton. Apart from that, the code is identical. Also, an error at line 1 is nonsensical. This may be a silly question, but is the page on the server up-to-date? Otherwise I haven't got a clue I'm afraid
My apologies, the error is on line 16 not line 1.

Fatal error: Call to undefined function: () in /home/breforml/public_html/db.php on line 16

Line 16 is this one:

16: $mysql_select_db($database, $connection);

Is there any reason why the persistent connection doesn't work? Are there any benefits by using a persistent connection instead of a regular one?
> 16: $mysql_select_db($database, $connection);

It seems that money does not bring happiness. $mysql... should be mysql...

Syntax-highlight should help against these.
Well spotted dufduf. As to the connection type, the simple answer is: I don't know.

To quote the manual:
=============================================
mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
=============================================

however, as to the pros and cons of this I'm not sure. I'd imagine persistent connections are quicker (you don't need to re-connect). I'm not sure if they are a drain on server/db resources, although I'd imagine that a large number would be undesirable
Thanks again.

Especially for your patience with a newbie such as myself. Will get cracking and let you know how things progress.
OK, we are back at the following:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/breforml/public_html/Mediproregister_checker.php on line 61

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/breforml/public_html/Mediproregister_checker.php on line 62
 
To refresh,

61: $email_check = mysql_num_rows($sql_email_check);
62: $username_check = mysql_num_rows($sql_username_check);


ASKER CERTIFIED SOLUTION
Avatar of Diablo84
Diablo84

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The form gets completed and when you hit the submit button, it goes to a blank page, no errors, nothing. In the browser address window it appears that the file is still stuck on the mediproregister_checker.php file.

How do I get past this?
Hi Guys

I am still desperate for help on this, but I think this question has gotten a bit long so I will close this one and continue my queries with a new question.

Thanks