Jump to content

Error with Large section of HTML In PHP script


Recommended Posts

Hi guys, I am having trouble executing a program that I am doing in a course. The _END is included to tell the compiler were php ends and html begins. When I run the program I am getting an unexpected EOF error. Could I use something else other than _END to include html on the same page as php? I tried separating the different sections of php script with the <php ? ?> tags but this does not work either. Please help. Here is the code: Revised code without the _END. I replaced them with <php ?> where php appears and <p> </P> where html appears.

<?php // sqltest.php

require_once 'login.php';

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

if(!$db_server) die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database, $db_server)

or die("Unable to connect to MySQL: " . mysql_error());

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

{

$isbn = get_post('isbn');

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

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

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

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

}

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

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

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

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

isset($_POST['isbn']))

{

 

$author = get_post('author');

$title = get_post('title');

$category = get_post('category');

$year = get_post('year');

$isbn = get_post('isbn');

$query = "INSERT INTO classics VALUES".

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

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

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

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

}

?>

 

<p> //html form enclosed with <p></p>

<form action="sqltest.php" method= "POST"><pre>

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

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

Category <input type="text" name="category" />

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

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

<input type = "submit" value="ADD RECORD"/>

</pre></form>

</p>

 

<?php

// section of php code enclosed with <?php>

{

$query = "SELECT * FROM classics";

$result = mysql_query($query);

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

$rows = mysql_num_rows($result);

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

{

$row = mysql_fetch_row($result);

<pre>

Author $row[0]

Title $row[1]

Category $row[2]

Year $row[3]

ISBN $row[4]

</pre>

}

?>

//anothether section of html enclosed with <p></p> tags

<p>

<form action="sqltest.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>

</p>

 

<?php

//final section of php script enclosed with <?php ?> tags

}

mysql_close($db_server);

function get_post($var)

{

return mysql_real_escape_string($_POST[$var]);

}

?>

Edited by HumbleApprentice
Link to post
Share on other sites

You should be able to close PHP blocks. There's no reason why this shouldn't work:

<?phpwhile(condition) {?><p>HTML</p><?php}?>

Link to post
Share on other sites

Hi Foxy, I enclosed the php sections with <?php ?> and the html sections with the <p> </p> tags as you suggested but it still does not work. I placed a ?> tag on line 46. I also enclosed the form on line 49 and 59 with <p> and </P>. I open the <?php tag on line 62 and close it on line ?> 88; enclosed the other form on line 89 and 95 with <p> and </p>. I then enclosed the last section of the php script that begins on line 97 and ends on line 108 with <?php?> . Where do you suggest that I put the while loop should I replace the for loop with it. I tried that but it does not work.

Link to post
Share on other sites
Guest So Called

I've read (and worked on) tons of PHP code and I've never once seen any _END thing. PHP files start out being interpreted exactly the same as HTML files except that the PHP parser is looking for <?php directives. Once seen it goes into PHP mode and executes rather than echoing. When it encounters the ?> directive it goes back into HTML mode (just echoing). It would be more helpful if you post your code using the forum's CODE tag, and use indentation for readability. Too bad the forum CODE tag does not add line numbers. My advice is to get rid of the _END stuff and repost your code within the proper tags. Maybe then we can find out why your code fails.

Link to post
Share on other sites
I've read (and worked on) tons of PHP code and I've never once seen any _END thing. PHP files start out being interpreted exactly the same as HTML files except that the PHP parser is looking for <?php directives. Once seen it goes into PHP mode and executes rather than echoing. When it encounters the ?> directive it goes back into HTML mode (just echoing). It would be more helpful if you post your code using the forum's CODE tag, and use indentation for readability. Too bad the forum CODE tag does not add line numbers. My advice is to get rid of the _END stuff and repost your code within the proper tags. Maybe then we can find out why your code fails.
The "_END" he's using is part of the heredoc syntax, in which you can surround a string like this:
$str = <<<IDENTIFIERString goes hereIDENTIFIER;

There can be no spaces before the closing "IDENTIFIER" The HTML does not need to be surrounded by <p> tags, that was just part of example HTML I was using. What error are you getting?

Link to post
Share on other sites

This is the error message: Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in C:\web\sqltest2.php on line 69It is complaining about the for loop and it is also complaining about the closing php tag at the end of the program

Edited by HumbleApprentice
Link to post
Share on other sites

About all I can say with that information is that it expects a "::" operator when it found a closing paren. There could be a few reasons for that, including trying to check if a constant is empty.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...