Is there a way to...

Status
Not open for further replies.

Baevus

the names ethan
Nov 4, 2012
565
47
This is what I want. I want to list all the usernames but it isn't working; Parse error: syntax error, unexpected T_STRING in /home/u523656928/public_html/Content/Scripts/membersmain.php on line 4. Is there a way to add a <?php tag in a <?php tag?

PHP:
<?php echo $_SESSION['id']?'Click on a members name to see their profile!<br/>
<?php include 'connect.php'
// Create connection
$conn = new sql($id, $username);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, username FROM Users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row["id"]. " - Username: ". $row["username"]. "<br>;
}
} else {
echo "There are no users registered!";
}
$conn->close(); ?>':'<i>If you are seeing this you are NOT logged in! Please do so by clicking Log In | Register!</i>';?>
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
First you have a PHP open tag inside another, which you don't do

Second, you never added a semicolon to the end of the include.

Clean the code up, and add proper indentation. :p
 

Baevus

the names ethan
Nov 4, 2012
565
47
I removed the PHP tags and error's are still coming up.
I tried doing this;
PHP:
<div id="Container">
<div class="Header">News</div>
<?php echo $_SESSION['id']?'include 'memberscode.php'':'<i>If you are seeing this you are NOT logged in! Please do so by clicking Log In | Register!</i>';?>
</div>
But it won't allow me to do include 'memberscode.php'':' because the ' ends the line.
 

brsy

nah mang
May 12, 2011
1,530
272
I didn't look at the actual functionality of the code, but I think I fixed all the syntax errors. I did this on my phone so idk.
PHP:
<?php echo $_SESSION['id']; ?> Click on a members name to see their profile!<br/>
<?php include 'connect.php';
// Create connection
$conn = new sql($id, $username);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, username FROM Users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row['id']. " - Username: ". $row['username']. "<br>";
}
} else {
echo "There are no users registered!";
}
$conn->close(); ?>

<i>If you are seeing this you are NOT logged in! Please do so by clicking Log In | Register!</i>
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
This code is just fucked, are you trying to make it so if the user is logged in it says they are, and then it shows a list of users, and if they aren't it shows the login/register
 

Baevus

the names ethan
Nov 4, 2012
565
47
This code is just fucked, are you trying to make it so if the user is logged in it says they are, and then it shows a list of users, and if they aren't it shows the login/register
Yes, but ducklings code fixed the SYNTAX errors.
 
Yes, but ducklings code fixed the SYNTAX errors.
If you are seeing this you are NOT logged in! Please do so by clicking Log In | Register! Even if you are logged in, I'll fix it up now guys! Thanks for the help :]
 

brsy

nah mang
May 12, 2011
1,530
272
Yes, but ducklings code fixed the SYNTAX errors.
 

If you are seeing this you are NOT logged in! Please do so by clicking Log In | Register! Even if you are logged in, I'll fix it up now guys! Thanks for the help :]
A "best answer" would be appreciated. Also, you need a if else statement to check if the user is logged in or not.
 

Baevus

the names ethan
Nov 4, 2012
565
47
Sorry to be annoying guys I'm going to be completley honest, I don't know how to hyperlink in PHP.
PHP:
$sql = "SELECT id, username FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "User ID: <b>" . $row["id"]. "</b> - Username: <b><a href="/'. $row["username"].".php"></a></b><br>";
    }
I tried that, also tried;
PHP:
<?php print ( '<a href="/'. $row["username"].".php"></a>'  );?>
 

Baevus

the names ethan
Nov 4, 2012
565
47
When you are requesting help, post any errors you get, don't just say you are getting an error.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/u523656928/public_html/Content/Scripts/membersmain.php on line 20
 

Baevus

the names ethan
Nov 4, 2012
565
47
Copy and paste line 20, it appears you are missing a ; at the end.
Original; echo "User ID: <b>" . $row["id"]. "</b> - Username: <b>" . $row["username"]. "</b><br>";
With your edit; echo "User ID: <b>" . $row["id"]. "</b> - Username: <b>echo '<a href="' . $row['username'] . '.php"></a>"';</b><br>";
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
What is this?

Your whole code is so fucked.

PHP:
echo 'User ID: <b>' . $row["id"] . '</b> - Username: <b><a href="' . $row["username"] . '.php"></a></b><br />';

You do not put echo inside another echo or a print.
 
Status
Not open for further replies.

Users who are viewing this thread

Top