Jump to content

Recommended Posts

I have a php string that I want to display if a user has logged in to my website. I cannot get it to work however. I think it is because I have php embedded within php tags. The code is below. Does anyone know how I could re arrange this to get it to work? Many thanks.

 

<?

 

if($logged_in){

  echo '<a href="tex.php?id=<?PHP echo $rows['id'] ?>"><?PHP echo $rows['title']." - <i>".$rows['author']."</i>" ?></a>';

}else{

  echo '<p class="logintext"><a href="main.php">Login / Register</a></p>';

 

?>

Link to comment
https://forums.phpfreaks.com/topic/147822-solved-nested-php-issue/
Share on other sites

when you echo something and insert php in the middle of the echo you have to end the echo where php code restarts.

 

something like that.

 

eg

 

$a = "world";

echo "hello ".$a.", nice to meet you!";

 

the dot is called conctacnation (something!) meaning "attaching"

so youll attaching ehcoed stuff to php stuff to form a big non php line (usually html)

 

echo "not php".$php."not php";

 

more so:

 

echo "<td id='bgColor' style='width: 10%'><a href='add.php?id=".$info['id']."'>;

 

notice the end of the above line

 

"'>;

 

it's

 

" + '>;

 

edit:

ill leave the post, better to teach a man to fish than to give him food ei

besides all this writing isnt going to waste

'Should fix you up.'

 

Thanks for your reply Premiso. I changed the code but when I do it does not build the string including the variables. ie. I only get the hyphen and when hovered over it does not add the id number to the link. So basically my link looks like this  - 

 

Here is the entire code:

 

<?

/* Include Files *********************/

session_start();

include("database.php");

include("login.php");

/*************************************/

?>

 

 

<?php

 

$host="localhost";

$username="username";

$password="password";

$db_name="db";

$tbl_name="tbl";

 

 

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

 

$sql="SELECT * FROM $tbl_name ORDER BY author DESC";

$result=mysql_query($sql);

 

 

while($rows=mysql_fetch_array($result)){

?>

 

 

 

 

<?

 

}

 

 

mysql_close();

?>

<?

if($logged_in){

  echo '<a href="tex.php?id=' . $rows['id'] . '">' . $rows['title'] . ' - <i>'.$rows['author'].'</i></a>';

}else{

  echo '<p class="logintext"><a href="main.php">Login / Register</a></p>';

}

 

?>

 

 

 

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.