User ID not detected in iframe

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

User ID not detected in iframe

Dear Admin I have a simple problem the id is not detected in:

Code: Select all

<iframe src="/Comments/user/Profile-E-Mail-Send.php?id=<?php echo $users[id];?>"


Php code:

Code: Select all

<?php 
  
include('../connection.php');

$id = (int) $_GET['id'];

$sql=mysqli_query($conn,"SELECT * FROM `user` WHERE id='" . $id . "' ");
$users=mysqli_fetch_assoc($sql);
?>

Code: Select all

<?php
// connect to the "tests" database
$conn = new mysqli('127.0.0.1', 'comments', '123456', 'comments');
// check connection
if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
}

$id = (int) $_GET['id'];

// SELECT sql query
$sql = "SELECT `id`, `email_privacy` FROM `user`  WHERE email_privacy='Only Members' OR email_privacy='' AND  id='" . $id . "' LIMIT 1 "; 
// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
  // output data of each row from $result
  while($row = $result->fetch_assoc()) {
    echo '<iframe src="/Comments/user/Privacy-E-Mail.php" 
width="300" height="300" frameborder="0" scrolling="no" 
align="top" marginwidth="0" marginheight="0" name="email">
</iframe>
<p> '. $row['email_privacy'] ;
  }
}
else {
  echo '<iframe src="/Comments/user/Profile-E-Mail-Send.php?id=<?php echo $users[id];?>" 
width="400" height="400" frameborder="0" scrolling="no" 
align="top" marginwidth="0" marginheight="0" name="email">
</iframe>';
}
$conn->close();
?>

Admin Posts: 805
Don't add "<?php echo.." into another "echo".
Try this:

Code: Select all

echo '<iframe src="/Comments/user/Profile-E-Mail-Send.php?id='.$users['id'].'" 
width="400" height="400" frameborder="0" scrolling="no" align="top" marginwidth="0" marginheight="0" name="email">
</iframe>';

JanMolendijk Posts: 282
Thank alot for the support `its working now`