error in my script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

error in my script

Post by mayanktalwar1988 »

Code: Select all

<?php
if (isset($_GET['id'])){
 
$host = "localhost";
$user = "root";
$pass = "";
$db = "ask";
 
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db,$con);
 
$id = $_GET['id'];
echo "<a href=\"create_topic.php?id=$id\">New topic</a>";
echo "<table border='0' width='100%'>";
 
$sql = mysql_query("SELECT * FROM topics WHERE cat_id='".$id."'");
while($row = mysql_fetch_array($sql)) {
echo "<tr><td><a href='show_reply.php?cat_id=\"$id\"&topic_id=\"$row['id']\"'>".htmlentities($row['title'])."</a></td></tr>
 
<tr><td><a href='mailto:".$row['mail']."'>".htmlentities($row['author'])."</a></td></tr>
<tr><td>".date("j/n - y",$row['date'])."</td></tr>";
}
 
 
 
echo "</table>";
 
mysql_close($con);
} else {
echo "invalid usage!";
}
?>


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\customo\topic.php on line 18
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: error in my script

Post by jackpf »

Try putting curly braces around $row['id'].
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: error in my script

Post by mayanktalwar1988 »

yes jack that worked but why the prevoius code didnt worked
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: error in my script

Post by mayanktalwar1988 »

jack i am building a simple forum..i have simple reply box..and i want to add clickable smileys just like phpbb forum ...how to do it..i know i am asking for more.. :D
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: error in my script

Post by jackpf »

mayanktalwar1988 wrote:yes jack that worked but why the prevoius code didnt worked
Idk, something to do with PHP not parsing arrays in double quotes very well I guess...you should always use curly braces, or concatenation when echoing arrays with double quotes. I personally use single quotes, just preference tbh.

And that would be javascript.

I've actually created my own forum, http://jackpf.co.uk/forum, and I have something similar to that (with bbcode rather than smileys though). If you just want it to place the smileys into a textarea, you could do something like this:

Code: Select all

 
function newSmiley(smiley)
{
document.getElementsByTagName('textarea')[0].innerHTML += ' '+smiley+' ';
}
 
However, if you want something more advanced, with selection areas, you can just take a look at my js.js file on my site. The code() function is what I wrote to handle selection areas, and inserting wherever the cursor currently is.
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: error in my script

Post by mayanktalwar1988 »

ok jack thanks...i got it
Post Reply