Forum Moderators: coopster

Message Too Old, No Replies

Parse error: syntax error, unexpected T CONSTANT ENCAPSED STRING,

         

Garath531

6:50 pm on Mar 9, 2007 (gmt 0)

10+ Year Member



I get this error message everytime i try to get to a page.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '$' in [path removed] on line 31

Here is my code.


<?php
//Registration form
function register_form(){
$date = date('D, M, Y');
echo "<form action='?act=register' method='post'>"
."Username: <input type='text' name='username' size='30'><br>"
."Password: <input type='password' name='password' size='30'><br>"
."Confirm your password: <input type='password' name='password_conf' size='30'><br>"
."Email: <input type='text' name='email' size='30'><br>"
."<input type='hidden' name='date' value='$date'>"
."<input type='submit' value='Register'>"
."</form>";
}
function register() {
$connect = mysql_connect(localhost, Securitized, securitized);
if (!$connect)
{
die(mysql_error());
}
$select_db = mysql_select_db(securitzed, $connect);
if (!$select_db) {
die(mysql_error());
}
//Collecting info
$username = $_POST['username'];
$password = $_POST['password'];
$pass_conf = $_POST['password_conf'];
$email = $_POST['email'];
$date = $_POST['date'];
//Here we will check do we have all inputs filled
if(empty('".$_REQUEST['username']."')){
die("Please enter your username!<br>");
}
if(empty('".$_REQUEST['password']."')){
die("Please enter your password!<br>");
}
if(empty('".$_REQUEST['password_conf']."')){
die("Please confirm your password!<br>");
}
if(empty('".$_REQUEST['email']."')){
die("Please enter your email!");
}
//Let's check if this username is already in use
$user_check = mysql_query("SELECT username FROM members WHERE username = '".$_REQUEST

['username']."'");
$do_user_check = mysql_num_rows($user_check);
//Now if email is already in use
$email_check = mysql_query("SELECT email FROM members WHERE email= '".REQUEST['email']."'");
$do_email_check = mysql_num_rows($email_check);
//Now display errors
if($do_user_check > 0){
die("Username is already in use!<br>");
}
if($do_email_check > 0){
die("Email is already in use!");
}
//Now let's check does passwords match
if('".$_REQUEST['password']."'!= '".$_REQUEST['password_conf']."'){
die("Passwords don't match!");
}
//If everything is okay let's register this user
$insert = mysql_query("INSERT INTO members (username, password, email)
VALUES ('".$_REQUEST['username']."', '".$_REQUEST['password']."', '".$_REQUEST['email']."')");
if(!$insert){
die("There's little problem: ".mysql_error());
}

echo '".$_REQUEST['username']."'", you are now registered. Thank you!<br><a href=?

act=login>Login</a> ¦ <a href=index.php>Index</a>";
}
switch($act){
default;
register_form();
break;
case "register";
register();
break;
}
?>

[edited by: Garath531 at 6:50 pm (utc) on Mar. 9, 2007]

jatar_k

6:56 pm on Mar 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Garath531,

I'm not sure why there are so many quotes on this line as they are unnecessary and also causing an error

change
if(empty('".$_REQUEST['username']."')){

to
if(empty($_REQUEST['username'])){

Garath531

7:49 pm on Mar 9, 2007 (gmt 0)

10+ Year Member



Thanks, it works, but for some reason, when I pust 'register' nothing happens.

ramoneguru

1:15 am on Mar 10, 2007 (gmt 0)

10+ Year Member



You didn't check to see if the 'Register' button was pressed. Go to php.net and look up the 'isset' function. The logic should go something like this:

if (isset(<button name from POST here>))
do processing and such
else
register_form()

--Nick

Garath531

5:11 pm on Mar 10, 2007 (gmt 0)

10+ Year Member



So,

if (isset($_POST['register'])) {
function register() {
$connect = mysql_connect(localhost, Securitized, securitized);
if (!$connect)
{
die(mysql_error());
}
$select_db = mysql_select_db(securitzed, $connect);
if (!$select_db) {
die(mysql_error());
}
//Collecting info
$username = $_POST['username'];
$password = $_POST['password'];
$pass_conf = $_POST['password_conf'];
$email = $_POST['email'];
$date = $_POST['date'];
//Here we will check do we have all inputs filled
if(empty('".$_REQUEST['username']."')){
die("Please enter your username!<br>");
}
if(empty('".$_REQUEST['password']."')){
die("Please enter your password!<br>");
}
if(empty('".$_REQUEST['password_conf']."')){
die("Please confirm your password!<br>");
}
if(empty('".$_REQUEST['email']."')){
die("Please enter your email!");
}
//Let's check if this username is already in use
$user_check = mysql_query("SELECT username FROM members WHERE username = '".$_REQUEST
['username']."'");
$do_user_check = mysql_num_rows($user_check);
//Now if email is already in use
$email_check = mysql_query("SELECT email FROM members WHERE email= '".REQUEST['email']."'");
$do_email_check = mysql_num_rows($email_check);
//Now display errors
if($do_user_check > 0){
die("Username is already in use!<br>");
}
if($do_email_check > 0){
die("Email is already in use!");
}
//Now let's check does passwords match
if('".$_REQUEST['password']."'!= '".$_REQUEST['password_conf']."'){
die("Passwords don't match!");
}
//If everything is okay let's register this user
$insert = mysql_query("INSERT INTO members (username, password, email)
VALUES ('".$_REQUEST['username']."', '".$_REQUEST['password']."', '".$_REQUEST['email']."')");
if(!$insert){
die("There's little problem: ".mysql_error());
}
echo '".$_REQUEST['username']."'", you are now registered. Thank you!<br><a href=?
act=login>Login</a> ¦ <a href=index.php>Index</a>";
}
switch($act){
default;
register_form();
break;
case "register";
register();
break;
} }
else {
register_form()
}

Should that work?

eelixduppy

5:36 pm on Mar 10, 2007 (gmt 0)



>> Should that work?

Have you tried it? ;)

Garath531

7:32 pm on Mar 10, 2007 (gmt 0)

10+ Year Member



I tried it with this,

<?php
//Registration form
function register_form(){
$date = date('D, M, Y');
echo "<form action='register.php' method='post'>"
."Username: <input type='text' name='username' size='30'><br>"
."Password: <input type='password' name='password' size='30'><br>"
."Confirm your password: <input type='password' name='password_conf' size='30'><br>"
."Email: <input type='text' name='email' size='30'><br>"
."<input type='hidden' name='date' value='$date'>"
."<input type='submit' value='Register' name='register'>"
."</form>";
}
function register() {
$connect = mysql_connect("localhost", "demonchat_garat", "rolyat");
if (!$connect)
{
die(mysql_error());
}
$select_db = mysql_select_db("demonchat_chat", $connect);
if (!$select_db) {
die(mysql_error());
}
//Collecting info
$username = $_POST['username'];
$password = $_POST['password'];
$pass_conf = $_POST['password_conf'];
$email = $_POST['email'];
$date = $_POST['date'];
//Here we will check do we have all inputs filled
if(empty($_REQUEST['username'])){
die("Please enter your username!<br>");
}
if(empty($_REQUEST['password'])){
die("Please enter your password!<br>");
}
if(empty($_REQUEST['password_conf'])){
die("Please confirm your password!<br>");
}
if(empty($_REQUEST['email'])){
die("Please enter your email!");
}
//Let's check if this username is already in use
$user_check = mysql_query("SELECT username FROM members WHERE username = '".$_REQUEST

['username']."'");
$do_user_check = mysql_num_rows($user_check);
//Now if email is already in use
$email_check = mysql_query("SELECT email FROM members WHERE email= '".$_REQUEST['email']."'");
$do_email_check = mysql_num_rows($email_check);
//Now display errors
if($do_user_check > 0){
die("Username is already in use!<br>");
}
if($do_email_check > 0){
die("Email is already in use!");
}
//Now let's check does passwords match
if($_REQUEST['password']!= $_REQUEST['password_conf']){
die("Passwords don't match!");
}
//If everything is okay let's register this user
$insert = mysql_query("INSERT INTO members (username, password, email)
VALUES ('".$_REQUEST['username']."', '".$_REQUEST['password']."', '".$_REQUEST['email']."')");
if(!$insert){
die("There's little problem: ".mysql_error());
}

echo $_REQUEST['username']; ", you are now registered. Thank you!<br>";
echo "<a href=act=login>Login</a> ¦ <a href=index.php>Index</a>";
}
switch($act){
default;
register_form();
break;
case "register";
register();
break;
}
if (isset($_POST['register'])){
register()
}
else {
register_form()
}
?>


But I get an error about an unexpected } on line 80.

jatar_k

8:31 pm on Mar 10, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the line number seems strange and I didn't really feel like counting braces to make sure they match, which you could do

I did notice that you are missing semi colons here

if (isset($_POST['register'])){
register()
}
else {
register_form()
}

both those function calls should end in a semi colon like so

if (isset($_POST['register'])){
register();
}
else {
register_form();
}

Garath531

12:31 am on Mar 11, 2007 (gmt 0)

10+ Year Member



Thanks. I put in the semi-colons and it worked.