Jump to content

[SOLVED] syntax error


pinochio

Recommended Posts

Hi I am having problems while debugging my code. When I am running it this is an error that I receive in my browser:

Parse error: syntax error, unexpected $end in c:\program files\apache group\Apache\htdocs\CT\getguestbook.php on line 40. Does anybody can help me out to with what exactly is wrong?

 

<?php
if (empty($_GET["Name"]) || empty($_GET["Email"]))
   die("<p> You must enter name and email. You need to go back to the Guestbook.</p>");

$DBConnect = @mysqli_connect("root", "", "")
	   Or die("<p>Unable to connect to the database server.</p>"
	   . "<p>Error code " . mysqli_connect_errno()
	   . ":" . mysqli_connect_error()) . "</p>";

$DBName = "guestbook"; //creating database
if (!@mysqli_select_db($DBConnect, $DBName)) {
   $SQLstring = "CREATE DATABASE $DBName";
   $QueryResult = @mysqli_query($DBConncet, $SQLstring);
   
mysqli_select_db($DBConnect, $DBName);
   
$TableName = "visitors";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = mysqli_query($DBConnect, $SQLstring);   
   if (!$QueryResult) {
   	  $SQLstring = "CREATE $TableName (countID SMALLINT NOT NULL AUTO INCREMENT PRIMARY KEY ,
  guest_name VARCHAR(40), guest_email VARCHAR(40))";
  $QueryResult = @mysqli_query($DBConnect, $SQLstring)
  or die("<p>Unable to create table .</p>"
  . "<p>Error Code " . mysqli_errno($DBConnect)
  . ":" . mysqli_error($DBConnect)) . "</p>";
  }

$Name = addslashes($_GET["Name"]);
$Email = addslashes($_GET["Email"]);
$SQLstring = "INSERT INTO $TableName VALUES(NULL, '$Name', '$Email')";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
		 or die("<p>Unable to execute query.</p>"
		 . "<p>Error Code " . mysqli_errno($DBConnect)
         . ":" . mysqli_error($DBConnect)) . "</p>";
echo "<h1>Thank you for signing our guestook.</h1>";
mysqli_close($DBConnect);
?>

Link to comment
https://forums.phpfreaks.com/topic/175888-solved-syntax-error/
Share on other sites

$end errors are generally caused by either missing or extra brackets ({, }). I popped your code into Notepad++ really fast and saw that the bracket on this line:

 

if (!@mysqli_select_db($DBConnect, $DBName)) {

isn't being closed anywhere.

Link to comment
https://forums.phpfreaks.com/topic/175888-solved-syntax-error/#findComment-926752
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.