Jump to content

Func and line error help


HaZaRd420

Recommended Posts

I am having trouble with my code and getting an error on a line that just has </html> on it.

[code]<?php


$func = $_GET["func"];

$id = $_GET["id"];

//hazards test//

include('config.php');



$rs = mysql_connect( "$host","$user","$pass" ) or die(mysql_error());

$rs = mysql_select_db( "$db" );

$rs = mysql_query($sql) or die(mysql_error());



if($func === 'view')

{

$sql="SELECT * FROM news where id='1'";

$rs = mysql_query($sql_staff) or die(mysql_error());

  echo"

<table id=\"Table_01\" width=\"314\" height=\"100\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">

    <tr>

        <td>

        <table background=\"box2/images/index_01.gif\" width="314" height=\"23\">

<tr>

<td><b>'.$row["subject"].'</b><br><br><div align=\"right\">Posted by : <b><u>'.$row["author"].'</u></b> on <i>'.$row["date"].'</i></div></td>

</tr>

</table>

            </td>

    </tr>

    <tr>

        <td>

        <table background=\"box2/images/index_02.gif\" width=\"314\" height=\"72\" cellpadding=\"5\">

<tr valign="top">

<td>

'.$row["content"].'

</td>

</tr>

</table>

            </td>

    </tr>

    <tr>

        <td>

            <img src=\"box2/images/index_03.gif\" width=\"314\" height=\"5\" alt=\"\"></td>

    </tr>

</table>

';

}

?>[/code]

any way someone can sort this out for me? All i want to do is display the data from that row. But im gettiing this error // Parse error: syntax error, unexpected $end in /data/11/0/78/25/730677/user/745722/htdocs/gau/test/news.php on line 99

thanks.
Link to comment
https://forums.phpfreaks.com/topic/11571-func-and-line-error-help/
Share on other sites

unexpected end happens when something is still open. this could be a line, if, loop, etc.

a few notes which could all be culprits:
$func = $_GET["func"]; // please use if (isset ($_GET)) $_GET = $var;
// as this can cause errors, not critical but anyway

mysql_connect( "$host","$user","$pass" ) // this does not need quotes for the $strings
mysql_select_db( "$db" ); // neither does this
$rs = mysql_query($sql_staff) or die(mysql_error()); // where is $sql_staff set?
'.$row["subject"].' // change this to ".$row['subject']." as you have opened the echo on "

With so much html you are better escaping php. this can simply things a lot.

<?
if ($page) {
?><html></html><?
}
?>

No need to addslashes so much.

Also $_var["attrib"] is better as $_var['attrib'] if you're using echo ""; standardize your quotes
The if ($page) was just an example of escaping to html within php. I'll show you what your page would look like:

[code]
<?php

$func = (isset ($_GET['func'])) ? $_GET['func'] : "";
$id = (isset ($_GET['id'])) ? $_GET['id'] : "";

//hazards test//

include ("config.php");

$rs = mysql_connect ($host, $user, $pass) or die (mysql_error ());
$rs = mysql_select_db ($db);
$rs = mysql_query ($sql) or die (mysql_error ());

if($func === "view")
{
    $sql_staff = "SELECT * FROM news where id=\'1\'"; // the issue was here, no slashes on the quotes inside the query
    $rs = mysql_query ($sql_staff) or die (mysql_error()); // $sql_staff was not defined?
?>
<table id="Table_01" width="314" height="100" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
        <table background="box2/images/index_01.gif" width="314" height="23">
    <tr>
    <td><b><?=$row['subject']?></b><br><br><div align="right">Posted by : <b><u><?=$row['author']?></u></b> on <i><?=$row['date']?></i></div></td>
    </tr>
    </table>
     </td>
    </tr>
    <tr>
     <td>
        <table background="box2/images/index_02.gif" width="314" height="72" cellpadding="5">
    <tr valign="top">
    <td><?=$row['content']?></td>
    </tr>
    </table>
     </td>
    </tr>
    <tr>
     <td>
        <img src="box2/images/index_03.gif" width="314" height="5" alt="">
     </td>
    </tr>
</table>
<?
}
?>
[/code]

As you can see, within the html we do <?=$var?> to get php vars
quoted from php.net:

Note on ===:

While the php documentation says that, basically,
($a===$b) is the same as ($a==$b && gettype($a) == gettype($b)),
this is not true.

The difference between == and === is that === never does any type conversion. So, while, according to documentation, ("+0.1" === ".1") should return true (because both are strings and == returns true), === actually returns false (which is good).

Edit: didn't want to post again. Obviously not needed but it's not my script.

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.