Forum Moderators: coopster
I'm fairly new to PHP, and am trying to write a script that will show the link to a user's profile as they post a message. This is the line that's giving me trouble:
echo('<div class=info><b>Link Added By: </b>'?><a href='http://www.example.com/to2/boards/whois.php?user=<?$userid?>'></a><?php . $row['username'] .' ¦ <b>Posted: </b>'. $row['time'] . ' ¦ <b>Rate this:</b> [+1] [-1] ¦ <b>Current Score: $score ¦</b></div>');
And my error:
Parse error: syntax error, unexpected ';' in /home/example.com/to2/boards/plink.php on line 22
If you need any more information, please ask.
Thanks.
[edited by: jatar_k at 5:38 pm (utc) on July 6, 2007]
[edit reason] please use example.com [/edit]
Your PHP has broken down by the end of this section...
echo('<div class=info><b>Link Added By: </b>'?><a
There is no closing bracket on the echo statement. Try changing the above as follows which may help:
echo('<div class=info><b>Link Added By: </b>');?><a
I've just noticed this very quickly and not studied the rest of your post. I assume that there is an opening PHP tag shortly before this segment.
from looking at that line, things look a little confused. You jump in and out of the parser and have some incorrect syntax.
my wild guess at the proper way to write that line is below
echo '<div class="info"><b>Link Added By: </b><a href="http://www.example.com/to2/boards/whois.php?user=' . $userid . '></a>' . $row['username'] .' ¦ <b>Posted: </b>' . $row['time'] . ' ¦ <b>Rate this:</b> [+1] [-1] ¦ <b>Current Score: ' . $score . ' ¦</b></div>';
see if that works for you
jatar_k, I was jumping out of the parser because I couldn't find a way to use variables in the URL, but the method you're suggesting seems to work, but something goes wrong. I get this:
Link Added By: PUT.
PUT is a hyperlink, and it links to this:
http://www.example.com/to2/boards/whois.php? user=%3E%3C/a%3EAdmin%20%20%3Cb%3EPosted:%20%3C/ b%3E2007-07-05%2019:43:31%20%20%3Cb%3ERate%20this:%3C/ b%3E%20[+1]%20[-1]%20%20%3Cb%3ECurrent%20Score:%20%3C/ b%3E%3C/div%3E%3Cdiv%20class=message%3ETESTINGOUTPUT.%20%3Cbr%3E%3Cbr%3E%2
So I'm thinking something didn't close right, and it added the SQL output into the link. Any thoughts?
[edited by: jatar_k at 7:18 pm (utc) on July 6, 2007]
[edit reason] sidescroll and example.com [/edit]
echo '<div class="info"><b>Link Added By: </b><a href="http://www.example.com/to2/boards/whois.php?user=' . $userid . '"></a>' . $row['username'] .' ¦ <b>Posted: </b>' . $row['time'] . ' ¦ <b>Rate this:</b> [+1] [-1] ¦ <b>Current Score: ' . $score . ' ¦</b></div>';
if that isn't it then there is a problem with a var somewhere
It's seeing it, but now the problem isn't with PHP, I believe it's with SQL. The link it's pointing to is http://www.example.com/to2/boards/whois.php?user=Resource%20id%20#41
Is that a problem wtih what I have in the database, or is that a PHP problem? It seems like SQL, because if I hardcode a variable in there, it works just fine.
Thanks.
[edited by: jatar_k at 9:01 pm (utc) on July 6, 2007]
maybe try this thread
Basics of extracting data from MySQL using PHP [webmasterworld.com]
<?php
require_once 'includes/header.inc.php';
if (!$_DATA['user']['auth'])
$page->error('login');
$linkid = $_POST['linkid'];
$userid = mysql_query("SELECT user_id FROM links WHERE link_id = $linkid");
$score = mysql_query("SELECT link_score FROM links WHERE link_id = $linkid");
$result = mysql_query("SELECT * FROM links")
or die(mysql_error());
$result = @mysql_query("SELECT * FROM links WHERE link_id = $linkid");
if (!$result) {
die('<p>Error performing query.' . mysql_error() .
'</p>');
}
while ( $row = mysql_fetch_array($result) ) {
echo ('<h1>' . $row['link_title'] . '</h1><br><br><br>');
echo '<div class="info"><b>Link Added By: </b><a href="http://www.example.com/to2/boards/whois.php?user=' . $userid . '">' . $row['username'] .'</a> ¦ <b>Posted: </b>' . $row['time'] . ' ¦ <b>Rate this:</b> [+1] [-1] ¦ <b>Current Score: ' . $score . ' </b>¦</div>';
echo('<div class=message>' . $row['link_message'] . '</div>');
}
?>
<?php
$page->footer();
?>
I made a connection in the header, and it looks like I have everything right. Other things called from the database using this script work fine, it's just the user_id isn't getting through. Any ideas?
[edited by: jatar_k at 9:21 pm (utc) on July 6, 2007]
$userid = mysql_query("SELECT user_id FROM links WHERE link_id = $linkid");
that won't give you the userid, you will have to extract it. All the mysql_query [php.net] function does is return a resource that points to your result set.
You would need to use something like mysql_fetch_array [php.net] to grab the actual data, as mentioned in that thread I linked to.
You will aslo have the same issue for a couple other of your queries.