Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
syntax error, unexpected end of file on line 44
i have tried to fix but i cant,so i need help
and can describe what is this error and how to fix it.

What I have tried:

PHP
  1  <!--Bahagian Borang Input Pengguna-->
  2  <?php if(empty($_POST['login'])) {?>   
  3      <p>Sila LOGIN untuk membuat tempahan homestay</p>
  4      <h3>Login Pelanggan</h3>
  5      <form action="login.php" method="POST">
  6      <input type="email" name="email"
  7      placeholder="email@mail.com"><br><br>
  8      <input type="text" name="pswd"
  9      placeholder="Katalaluan"><br><br>
 10      <input type="submit" name="login" value="LOGIN"><br>
 11      </form>
 12      <p>Jika belum mendaftar klik <a href="daftar.php"> di sini.</a></p>
 13      <?php}else{
 14      //Bahagian Proses Data
 15      $email=$_POST['email'];
 16      $pswd=$_POST['pswd'];
 17      //Sambung Fail ke DBMS
 18      include 'capaian.php';
 19      if(!$connect){
 20          echo "DBMS gagal dicapai.";
 21      }
 22      //Query
 23      $query="select* from pelanggan where '$email'=email
 24      AND '$pswd'=katalaluan";
 25      //Laksanakan Query
 26      $run=mysqli_query($connect,$query);
 27      //Panggil Data
 28      $data=mysqli_fetch_array($run);
 29      $id=$data['idpelanggan'];
 30      $nama=$dat['nama'];
 31      //Dialog Login Gagal	
 32      if($id == 0){
 33      	echo "Maaf,".$nama."anda gagal login";
 34      	echo "<br>Sila login semula <a href='login.php'> di sini</a>";
 35      	//Dialog Login Berjaya
 36      }else{
 37      	echo "Tahniah,".$nama." berjaya login";
 38      	echo "<br>Sila klik <a href='tempahan.php ?id=
 39      	".$id."&&nama=".$nama."'>di sini</a>
 40      	untuk tempahan homestay";
 41      }
 42      mysqli_close($connect);
 43  }?>
Posted
Updated 30-Jun-20 22:04pm
v3
Comments
Kornfeld Eliyahu Peter 29-Jun-20 9:52am    
Pay attention that line 44 is not that 44 in your code sample... You have an include in the way...
Richard MacCutchan 29-Jun-20 9:56am    
I have scanned your code three times but I still cannot see the error.
[no name] 29-Jun-20 12:40pm    
See my comment below. Can that be the reason? If yes feel free to answer.
Richard MacCutchan 29-Jun-20 13:04pm    
Yes, I think that is the answer.
[no name] 29-Jun-20 12:33pm    
I don't know php at all. But with an online syntax checker for me it gives no error in case I replace line 15
<?php}else{
with
<?php }else{

I only know php from a few small examples that I have tested, so please be careful with my answer.

With an online syntax checker for me it gives finally no error in case I replace line 15
<?php}else{
with
<?php }else{

I hope it helps.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 30-Jun-20 1:16am    
Sharp eyes!!!
It is not really emphasized nowhere (not even on the official documentation), but the syntax for the opening and closing tags are
<?php[witespace] and [whitespace]?>
[no name] 30-Jun-20 6:51am    
Thank you, but it was not me it was an online php syntax checker :)
This is more for future readers on the same subject -

PHP is quite sensitive to its initiation of code and totally ignorant to the actual code contained inside its initiation blocks, here are some samples -

It is always good to get into the habit of breaking your lines down with white-space to prevent what happened here when breaking in and out of php code blocks
PHP
<?PHP
}
else
{
?>


Some more info on different options when breaking in and out of blocks -

Escaping to PHP
The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as 'escaping to PHP'. There are four ways to do this −

Canonical PHP tags
The most universally effective PHP tag style is −>
<?php...?>


If you use this style, you can be positive that your tags will always be correctly interpreted.

Short-open (SGML-style) tags
Short or short-open tags look like this −
<?...?>


Short tags are, as one might expect, the shortest option You must do one of two things to enable PHP to recognize the tags −

Choose the --enable-short-tags configuration option when you're building PHP.

Set the short_open_tag setting in your php.ini file to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags.

HTML script tags
HTML script tags look like this −
<script language = "PHP">...</script>


PHP is whitespace insensitive
Whitespace is the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns (end-of-line characters).

PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row.one whitespace character is the same as many such characters.

For example, each of the following PHP statements that assigns the sum of 2 + 2 to the variable $four is equivalent −
$four = 2 + 2; // single spaces
$four <tab>=<tab2<tab>+<tab>2 ; // spaces and tabs
$four =
2+
2; // multiple lines


Braces make blocks
Although statements cannot be combined like expressions, you can always put a sequence of statements anywhere a statement can go by enclosing them in a set of curly braces.

Here both statements are equivalent −
if (3 == 2 + 1)
   print("Good - I haven't totally lost my mind.<br>");
   
if (3 == 2 + 1) {
   print("Good - I haven't totally");
   print("lost my mind.<br>");
}


I hope this will help future readers on some basics.
 
Share this answer
 
Comments
Richard MacCutchan 1-Jul-20 4:47am    
Very useful answer. All we need now is some way to force people to search for it.
Andre Oosthuizen 1-Jul-20 5:10am    
Thank you Richard, much appreciated!
As far as the searching goes, I agree 100%, not a common attribute for people with problems it seems (tongue in cheek).
Something like this is almost always caused by mismatched tags, curly braces, or parenthesis, or by a missing semicolon somewhere.

I've looked over the code multiple times, but can't see what is wrong with it, but then again, I don't do PHP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900