Click here to Skip to main content
14,580,263 members
Rate this:
Please Sign up or sign in to vote.
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:

  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"
  8      placeholder=""><br><br>
  9      <input type="text" name="pswd"
 11      placeholder="Katalaluan"><br><br>
 12      <input type="submit" name="login" value="LOGIN"><br>
 13      </form>
 14      <p>Jika belum mendaftar klik <a href="daftar.php"> di sini.</a></p>
 15      <?php}else{
 16      //Bahagian Proses Data
 17      $email=$_POST['email'];
 18      $pswd=$_POST['pswd'];
 19      //Sambung Fail ke DBMS
 20      include 'capaian.php';
 21      if(!$connect){
 22          echo "DBMS gagal dicapai.";
 23      }
 24      //Query
 25      $query="select* from pelanggan where '$email'=email
 26      AND '$pswd'=katalaluan";
 27      //Laksanakan Query
 28      $run=mysqli_query($connect,$query);
 29      //Panggil Data
 30      $data=mysqli_fetch_array($run);
 31      $id=$data['idpelanggan'];
 32      $nama=$dat['nama'];
 33      //Dialog Login Gagal	
 34      if($id == 0){
 35      	echo "Maaf,".$nama."anda gagal login";
 36      	echo "<br>Sila login semula <a href='login.php'> di sini</a>";
 37      	//Dialog Login Berjaya
 38      }else{
 39      	echo "Tahniah,".$nama." berjaya login";
 40      	echo "<br>Sila klik <a href='tempahan.php ?id=
 41      	".$id."&&nama=".$nama."'>di sini</a>
 42      	untuk tempahan homestay";
 43      }
 44      mysqli_close($connect);
 45  }?>
Updated 30-Jun-20 22:04pm
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.
0x01AA 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.
0x01AA 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{
Rate this:
Please Sign up or sign in to vote.

Solution 1

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{

I hope it helps.
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]?>
0x01AA 30-Jun-20 6:51am
Thank you, but it was not me it was an online php syntax checker :)
Rate this:
Please Sign up or sign in to vote.

Solution 3

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

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 −>

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 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; // 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.
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).
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100