The above code I am running with xamp. When ever I am removing the block (/**/) from the java script it is giving me error "Parse error: syntax error, unexpected $end in N:\PHP all\xampp\htdocs\Login2\show.php on line 55". But when my friend is running this code in his machine it is running perfectly well and good... Can any one help me with this issue. I dont know is there any particular place for php help. So I am sending it here.Thanks

Bigwebmaster

Site Admin

Posts: 9105

Loc: Seattle, WA & Phoenix, AZ

3+ Months Ago

After line 55 try hitting the return key one more time (probably won't fix it but it may, as it has in weird circumstances in the past for me). The most likely issue here is that there are typically 3 formats that text files are saved in: Windows Format, Unix Format, or Mac Format. The differences between the formats are how they end each line. For instance Windows typically uses the sequence of a carriage return and linefeed (CR/LF), Unix typically uses just a linefeed (LF) to end a line, and Macintosh uses just a carriage return (CR) to end a line. This can cause weird and unexpected error messages that are hard to diagnose if you do not know about this. Wikipedia has an excellent article on Newlines that you might want to read about. I will quote a few of the important parts I think that might help explain what I think is causing your situation:

Quote:

The different newline conventions often cause text files that have been transferred between systems of different types to be displayed incorrectly. For example, files originating on Unix or Apple Macintosh systems may appear as a single long line on some Windows programs. Conversely, when viewing a file originating from a Windows computer on a Unix system, the extra CR may be displayed as ^M at the end of each line or as a second line break.

The problem can be hard to spot if some programs handle the foreign newlines properly while others do not. For example, a compiler may fail with obscure syntax errors even though the source file looks correct when displayed on the console or in an editor.

I am not positive, but I have a hunch this is what is going on with you. Let us know what you find out

joy1986joy

Novice

Posts: 27

3+ Months Ago

When I am hitting a return key it is always giving me the error at the last line and the error is same. Another thing is we both using same O.S.

joebert

Fart Bubbles

Posts: 13506

Loc: Florida

3+ Months Ago

Compare the values of the php configuration option short_open_tag from both servers. On the server that gives you the error, the value is probably "off" and it's probably "on" for the server where it does work.

joy1986joy

Novice

Posts: 27

3+ Months Ago

No....actually my other php programs which are without java script they are running fine....I am using dreamweaver 8 for coading....

joebert

Fart Bubbles

Posts: 13506

Loc: Florida

3+ Months Ago

Seriously, I can reproduce the problem you describe by toggling the value of short_open_tag.

<?phpsession_start();$link=mysql_connect('localhost','root') or die('Connection Failed');mysql_select_db('customer',$link) or die('Could not connect to database');$query="select * from registration where password='{$_POST['password']}' and name='{$_POST['name']}'";$result=mysql_query($query);if(mysql_num_rows($result)>0){$_SESSION['name']=$_POST['name'];header('Location: /index.php');exit();}else{echo'<script>alert("You have entered the validation code incorrectly, please try again.")</script>';header('Location: /login.php');//or whatever the previous page is - this for me is better than the javascript appoachexit();}?>

<?php

session_start();

$link=mysql_connect('localhost','root') or die('Connection Failed');

mysql_select_db('customer',$link) or die('Could not connect to database');

$query="select * from registration where password='{$_POST['password']}' and name='{$_POST['name']}'";

header('Location: /login.php');//or whatever the previous page is - this for me is better than the javascript appoach

exit();

}

?>

Also, where is your password for the mysql_connect function?

joy1986joy

Novice

Posts: 27

3+ Months Ago

Actually above code is running only with Php....But I need to run the /*.. .*/ Part of script also...Which is a Java script...It is not running with the Java script which I have quoted. I need to run the Java script also with the Php code..

righteous_trespasser

Scuffle

Posts: 6229

Loc: South-Africa

3+ Months Ago

That's where you're incorrect sir ... you don't need the javascript at all ... I have replaced your javascript with the PHP equivalent ...

<?phpsession_start();$link=mysql_connect('localhost','root') or die('Connection Failed');mysql_select_db('customer',$link) or die('Could not connect to database');$query="select * from registration where password='{$_POST['password']}' and name='{$_POST['name']}'";$result=mysql_query($query);if(mysql_num_rows($result)>0){$_SESSION['name']=$_POST['name'];header('Location: /index.php');exit();}else{echo'<script>alert("You have entered the validation code incorrectly, please try again.")</script>';//here you can add some better code ...header('Location: /login.php');//or whatever the previous page is - this for me is better than the javascript appoachexit();}?>

<?php

session_start();

$link=mysql_connect('localhost','root') or die('Connection Failed');

mysql_select_db('customer',$link) or die('Could not connect to database');

$query="select * from registration where password='{$_POST['password']}' and name='{$_POST['name']}'";

header('Location: /login.php');//or whatever the previous page is - this for me is better than the javascript appoach

exit();

}

?>

And no I am glad when people ask questions and learn something from it, that's one of the only ways to learn if you don't know what to look for on google ...

joebert

Fart Bubbles

Posts: 13506

Loc: Florida

3+ Months Ago

You guys are learning that instead of figuring out what the problem was to begin with, to just spend a bunch of time working around it.

If you looked at the short_open_tag directive and didn't fix your error, then you did something wrong. I executed the code over here before I made my suggestion.

I can execute the code you posted, with the comments around the Javascript removed, and short_open_tag turned OFF and I get the error. As soon as I turn short_open_tag ON the error goes away.

Chances are that you either are not allowed to alter the PHP directives with your host and aren't saying anything about that, or you tried to change it and never checked to see if the change was actually being applied by executing phpinfo() within the same file you were testing.

The bottom line is that the problem, the original problem in this thread, was the setting of short_open_tag and the fact that although the first<?php token included the php part, subsequent tokens did not, they were short open tags AKA <?.

If you're having a problem deciphering that directive, try replacing all of your occurrences of plain <? with <?php and watch your code magically quit giving you that "unexpected $end" error.

If you want to waste you, or your employers time *peach* around with workarounds that don't address the original problem and not learn anything, fine. You're not going to sit here and toss my answer, which was the correct answer, away because you don't know what you're doing though.

joy1986joy

Novice

Posts: 27

3+ Months Ago

joebert wrote:

If you're having a problem deciphering that directive, try replacing all of your occurrences of plain <? with <?php and watch your code magically quit giving you that "unexpected $end" error.

You are right. If I use <?php in place of <? it is running. Thanks joebert