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
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

a quick question related to this. Why are you using === instead of == as === just means equivalent to. Unless there's some special feature of the === operator when comparing strings (such as case-insensitive?) that I'm not aware of
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.