Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello, i cant execute my php code cause an unexpected eof. The problem is that all the brackets are closed well so i dont know what to do
PHP
  1  <?php
  2  include("config.php");
  3  session_start();
  4   if(empty($_SESSION)){
  5     header("location: login.php");
  6   }
  7  ?>
  8  <html>
  9  <body>
 10  <?php
 11  if(!isset($_SESSION["username"])){
 12     header("location: login.php");
 13   }
 14  if(isset($_GET["intestazione"])){
 15   echo $_GET["intestazione"];
 16   if(isset($_POST["newpost"])){
 17    $intestazione=inputconvalid($_GET["intestazione"]);
 18    $post=inputconvalid($_POST["newpost"]);
 19    $link=$site."/topicdiscusso.php?intestazione=".$intestazione.";
 20    $sql='INSERT INTO Posts VALUES ('".$intestazione."','".$post."','".$_SESSION["username"]."','".$link."')';
 21    $conn->query($sql);
 22   }
 23  }
 24   $sql='SELECT Post,intestazione,username FROM Posts WHERE intestazione=='".$intestazione."'';
 25   echo $sql;
 26   $result = $conn->query($sql);
 27   if($result->num_rows > 0){
 28        $i=0;
 29        while($row = $result->fetch_assoc()) {
 30        if($i=0){
 31         echo '
 32      <div>
 33      <div>
 34       <h1>".$row["intestazione"]."</h1>
 35      </div>
 36      <div>
 37       <a align=\"left\">".$row["username"]."</a>
 38       <a align=\"center\"><h1>".$row["post"]."</h1></a>
 39      </div>
 40      </div>
 41      ' ;
 42       }else{
 43         echo '
 44          <div>
 45       <a align=\"left\">".$row["username"]."</a>
 46       <a align=\"center\"><h1>".$row["post"]."</h1></a>
 47      </div>
 48         '; 
 49       }
 50      $i++;
 51      }
 52   }?>


What I have tried:

i tried to look for the brackets and then close them
Posted
Updated 4-Jun-21 23:20pm
v4
Comments
Richard MacCutchan 4-Jun-21 7:46am    
There is something missing somewhere in your secret code.
Patrice T 4-Jun-21 15:43pm    
Post your code in question.
Use Improve question to update your question.

I added the correct language type and line numbering to the opening <pre> tag. It is now clear that lines 20 and 24 have an extra single quote at the end of the line, that should not be there.
 
Share this answer
 
Comments
Riccardo Miccinilli 5-Jun-21 5:38am    
it's not extra at the line 20
Richard MacCutchan 5-Jun-21 5:59am    
You are correct, my mistake based on the editor's syntax colouring. But I think line 19 may actually be the problem; it has three double quotes.
How do you expect anyone to try and fix a problem with code he can't see?

This is something you need to sort out yourself, and it's not just brackets that can cause it: an "open" string, a missing ")", or even a missing "?>" (for web based code) will cause the same error.

So start by looking closely, and if you still can't find it make a copy of your file and remove pretty much everything. When treh error disappears, put things back a function at a time until it comes back. When you know which smaller chunk of code causes it, repeat the operation for that function until it's obvious what it is.

Sorry, but we can't do any of that for you!
 
Share this answer
 
Comments
Riccardo Miccinilli 4-Jun-21 15:13pm    
query($sql);
}
}
$sql='SELECT Post,intestazione,username FROM Posts WHERE intestazione=='".$intestazione."'';
echo $sql;
$result = $conn->query($sql);
if($result->num_rows > 0){
$i=0;
while($row = $result->fetch_assoc()) {
if($i=0){
echo '


'".$row['intestazione']."'




'".$row["username"]."'

'".$row["post"]."'




' ;
}else{
echo '

".$row["username"]."

".$row["post"]."



';
}
$i++;
}
}

?>

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