Jump to content


Photo

Func and line error help


  • Please log in to reply
7 replies to this topic

#1 HaZaRd420

HaZaRd420
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 09 June 2006 - 12:35 PM

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

<?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>

';

}

?>

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.

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 09 June 2006 - 12:50 PM

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
z..z..z..z..z..z..z..z..

#3 HaZaRd420

HaZaRd420
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 09 June 2006 - 01:00 PM

K so escaping php is that a differnt method? if so, the if ($page) would be the name of my page that im creating?

#4 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 09 June 2006 - 01:11 PM

The if ($page) was just an example of escaping to html within php. I'll show you what your page would look like:

<?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>
<?
}
?>

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

#5 HaZaRd420

HaZaRd420
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 09 June 2006 - 01:17 PM

Sweet man I got it! Thanks alot for sparing your time to help me joquius. I may ask you for a few more questions in the future. Do you have any sort of instantmessaging program? if so contact me with a pm or somthing ! Thanks alot.

#6 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 02:03 PM

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
[table]



Don't worry, the printer fairies will sort it out.

#7 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 09 June 2006 - 02:10 PM

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.
z..z..z..z..z..z..z..z..

#8 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 02:15 PM

but if you're comparing it to a string, 'view', the only possible thing that could match that would be another 'view'.
[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users