• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

can anyone tell me whats wrong with this PHP line?

dabuddha

Lifer
i can't figure it out
i'm still a early beginner in PHP but heres what i have

echo '<TR><TD><A HREF=moduser.php?userid=' . $row["username"] . '>' . $row["username"] . '</A></TD><TD>' . $row["email"] . '</TD></TR>';

what im trying is to have the link point to moduser.php?userid
problem is when i run it and put my mouse over it, i get this as the URL
http://www.domain.net/moduser.php?userid=first

the correct userid is "first last" I dont really care if it puts the www.domain.net in front of the URL but why does it do that? I can't find any documentation on this. (maybe cause im not sure where to look 🙂 )
i tried putting quotes around moduser and the username like this:

echo '<TR><TD><A HREF=\"moduser.php?userid=' . $row["username"] . '\">' . $row["username"] . '</A></TD><TD>' . $row["email"] . '</TD></TR>';

but that just gives me this:
http://www.domain.net/"moduser.php?userid=first (for users with 2 words for their userid)
http://www.sanika.net/"moduser.php?userid=first\" (for users with 1 word for their userid)

tia 🙂
 
Since you are just beginning to learn PHP, I would suggest you follow the "accepted" way of using array indices. Don't use any quotes for array indices and if you insist on using it then put curly brackets, {}, around the whole variable. ie: {$row['username']}

That being said, try rewriting your echo statement as follow:

<?
$username = str_replace(" ", "%20",$row[username]);

echo "<tr><td><a href=\"moduser.php?userid=$username\">$row[username]</a></td><td>$row</td></tr>";
?>

The problem is probably because of the empty space in the username that's causing the problem. The above code will change the empty space with its URL friendly equivalent code.
 
ahh lemme try that
im probably going about it the wrong way but the way im learning is by looking at other people's code and modifying and scrutinizing it.
my books are still being shipped from amazon.com 🙂
 
Originally posted by: kt
Since you are just beginning to learn PHP, I would suggest you follow the "accepted" way of using array indices. Don't use any quotes for array indices and if you insist on using it then put curly brackets, {}, around the whole variable. ie: {$row['username']}

That being said, try rewriting your echo statement as follow:

<?
$username = str_replace(" ", "%20",$row[username]);

echo "<tr><td><a href=\"moduser.php?userid=$username\">$row[username]</a></td><td>$row</td></tr>";
?>

The problem is probably because of the empty space in the username that's causing the problem. The above code will change the empty space with its URL friendly equivalent code.[/quote]

A more efficient way of achieving the above is thus...

<?
echo "<tr><td><a href=\"moduser.php?userid=".urlencode($row[username])."\">$row[username]</a></td><td>$row[email]</td></tr>";
?>

teknodude
 
btw that worked great 🙂
now tomorrow im gonna figure out how to grab the username and query the database so i can make changed to that user
scarily this stuff is fun!
nice change from c++/X-motif programming
 
Originally posted by: dabuddha
ok one thing im little confused about...
for echo statements can you use ' and "
?

Yes, you may use single and double quotes for echo statements. But I prefer to use double quotes.. just a personal preference.

echo 'hello';
echo "hello";

Same thing.
 
Just a few notes, first off what kt said here:

Since you are just beginning to learn PHP, I would suggest you follow the "accepted" way of using array indices. Don't use any quotes for array indices and if you insist on using it then put curly brackets, {}, around the whole variable. ie: {$row['username']}

You should only NOT USE quotes when you are refering to a numerical index, ie $arrayname[0] or $arrayname[4], you should ALWAYS use quotes with associative arrays, ie $arrayname['firstname'] or $arrayname['lastname']

What kt said about the 'accepted' method of quotes in array keys is wrong. From the PHP MANUAL here:
http://www.php.net/manual/en/language.types.array.php

You should always use quotes around an associative array index. For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong?

<?php
$foo[bar] = 'enemy';
echo $foo[bar];
// etc
?>


This is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant (bar) rather than a string ('bar' - notice the quotes), and PHP may in future define constants which, unfortunately for your code, have the same name. It works, because the undefined constant gets converted to a string of the same name automatically for backward compatibility reasons.



Secondly, you're problem is that stupid space in the querystring variable, try using url_encode(); ( http://www.php.net/url_encode ) like the others said.

Just a few other thoughts, to be valid XHTML all of your HTML/XHTML should be in lowercase, NOT UPPERCASE. Also, all attributes should be quoted in HTML, so you should never have href=link.php, it should always be href="link.php"

Also, you can always use ' or " quotes in echo or in print, I *believe* the difference is that if you do:

print (' my name is $variablename ');

as opposed to:

print (" my name is $variablename ");


The first example WILL NOT evaluate that variable outk, intstead it will actually print $variablename instead of ' Keith ' or ' DaBuddha ' or wahtever. Hope that helps!
 
wow thanks for the info everyone
ill definitely check it out
I didn't know that about the difference between " and '. i think ill start using " now
 
Back
Top