Jump to content

Help please - Parse error: syntax error, unexpected $end in C:\web\update_data_t


Recommended Posts

Hi I am just starting to learn PHP and I am banging my head against the wall because I get

 

Parse error: syntax error, unexpected $end in C:\web\update_data_test.php on line 94

 

somewhere in....

 

<?php

 

require_once 'login.php';

 

$db_server = mysql_connect ($db_hostname, $db_username, $db_password);

 

if (!$db_server) die("Unable to connect to server, check username in login.php:" .mysql.error());

 

else echo "Connection to server sucessfull <br>" ;

 

mysql_select_db($db_database, $db_server)

or die ("Connection to database failed: " . mysql_error());

 

 

if (isset($_POST['author']) &&

isset($_POST['title']) &&

isset($_POST['catergory']) &&

isset($_POST['year']) &&

isset($_POST['isbn']))

{

 

$author = get_post('author');

$title = get_post('title');

$catergory = get_post('catergory');

$year = get_post('year');

$isbn = get_post('isbn');

 

if (isset($_POST['delete']) && $isbn !="")

{

$query = "DELETE FROM danielsbooks WHERE isbn='$isbn'";

 

 

if (!mysql_query($query, $db_server))

echo "DELETE failed: $query <br />".

mysql_error() . "<br /><br />";

}

else

{

  $query ="INSERT INTO danielsbooks VALUES" .

  "('$author', '$title','$catergory','$year','$isbn')";

 

  if (!mysql_query($query, $db_server))

  echo "INSERT failed: $query <br>".

  mysql_error(). "<br><br>";

}

 

}

 

echo <<<_END

<form action="update_data_test.php" method="post"> <pre>

Author <input type="text" name="author" />

Title <input type="text" name="title" />

catergory <input type="text" name="catergory" />

year <input type="text" name="year" />

isbn <input type="text" name="isbn" />

<input type="submit" Value="ADD RECORD" >

</pre> </form>

_END;

 

 

$query = "SELECT * FROM danielsbooks";

$result = mysql_query($query);

 

if (!$result) die ("Database access failed: " . mysql_error());

$rows = mysql_num_rows($result);

 

for ($j = 0; $j < $rows ; ++$j)

{

$row = mysql_fetch_row($result);

echo <<<_END

 

<pre>

Author $row[0]

Title $row[1]

Catergory $row[2]

Year $row[3]

isbn $row[4]

</pre>

 

<form action "update_data_test.php" method ="post">

<input type="hidden" name="delete" value="yes" />

<input type="hidden" name="isbn" value="$row[4]" />

<input type="submit" value="DELETE RECORD" /> </form>

_END;

}

 

mysql_close($db_server);

 

function get_post($var)

{

return mysql_real_escape_string($_POST[$var]);

}

 

?>

It looks like it is your heredoc syntax causing the problem.  See here: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

 

I can't recall if you can use the '_' character in the heredoc trigger.  Try without it and also make sure there is no whitespace whatsoever before the closing heredoc tag:

 

print <<<EOT
     your stuff here..
EOT;
// notice how there is no space before EOT;

 

Hope this helps.

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.