dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: How To Display In iFrame A Url From Mysql ?

  1. #1
    Join Date
    Oct 2016
    Posts
    109

    Question How To Display In iFrame A Url From Mysql ?

    Here is latest update of the code but still it shows not the variable value as the iframe url. Variable calls db row data.
    iFrame supposed to open to the url mentioned in the variable. The variable gets the data from the db row: Latest_View.
    I get no errors, though!

    PHP Code:

    <html>
    <head>
    <title>
    <?php
    $user Home Page
    ?>
    </title>
    </head>
    <body>
    <body background=".png">

    <?php
    session_start
    ();
    require 
    "conn.php";

    /*Check if user is logged-in or not by checking if session is set or not. 
    If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

    if(!isset($_SESSION["user"])) 
    {
        
    header("location:login.php");
    }
    else 
    {
        
    $user $_SESSION["user"];
        
    $sql "SELECT * FROM $user WHERE Username = '".$user."'";
        
    $result $conn->query($sql);
        while(
    $row $result->fetch_assoc()) 
        {
            
    $db_id $row["Id"];
            
    $db_username $row["Username"];
            
    $db_forename $row["Forename"];
            
    $db_surname $row["Surname"];
            
    $db_email $row["Email"];
            
    $db_bio $row["Bio"];
            
    $db_latest_view $row["Latest_View"];
        
        
            
    //Welcome user by name.
            
    echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

            <?php
            
    //Display log-out link.
            
    echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
        
            <?php 
            
    //Display User Bio.
            
    echo "<br><b>Bio:</b><br>";
            echo 
    "$db_bio";?><br>
            <br>
            
            <?php 
            
    //Display User's Latest View.
            
    echo "<br><b>Latest View:</b><br>";
            echo 
    "$db_latest_view";?><br>
            <br>

            <?php 
            
    //Display User's Latest Viewed Url in iFrame.?>
            <iframe src="<?php $db_latest_view;?>"></iframe>
            <?php             
        
    }
    }
    ?>

    </body>
    </html>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,928
    You need to echo the value;
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Oct 2016
    Posts
    109
    Quote Originally Posted by NogDog View Post
    You need to echo the value;
    Expecting the iFrame to open to the url that is listed in the row (pos:0) in the LATEST_VIEW column in mysql.

    Url in db is valid:
    https://www.youtube.com/playlist?lis...NcNTzUgYg_yG-U


    I know the 3rd one is invalid but still tried just incase I'm forgetting things.
    Any suggestions what the code should look like now ?

    A programmer suggested:
    <iframe src="<?=$db_latest_view?>">

    He and another suggested:
    <iframe src="<?php echo $db_latest_view;?>">

    But is not the double quotes supposed to be there like so (which I tried)?
    <iframe src="<?php echo "$db_latest_view";?>">

    Tried also the following when the above did not work:
    <iframe src="<?php echo \"$db_latest_view\";?>">

    Also tried another programmer's suggestion but no luck:
    <?php
    //Display User's Latest Viewed Url in iFrame.?>
    <iframe src='<?php echo $db_latest_view;?>'></iframe>
    <?php


    Here latest full code:

    PHP Code:
    <html>
    <head>
    <title>
    <?php 
    $user?>
     Home Page
    </title>
    </head>
    <body>
    <body background=".png">

    <?php
    session_start
    ();
    require 
    "conn.php";

    /*Check if user is logged-in or not by checking if session is set or not. 
    If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

    if(!isset($_SESSION["user"])) 
    {
        
    header("location:login.php");
    }
    else 
    {
        
    $user $_SESSION["user"];
        
    $sql "SELECT * FROM $user WHERE Username = '".$user."'";
        
    $result $conn->query($sql);
        while(
    $row $result->fetch_assoc())
        {
            
    $db_id $row["Id"];
            
    $db_username $row["Username"];
            
    $db_forename $row["Forename"];
            
    $db_surname $row["Surname"];
            
    $db_email $row["Email"];
            
    $db_bio $row["Bio"];
            
    $db_status_to_friends $row["Status_To_Friends"];
            
    $db_status_to_public $row["Status_To_Public"];
            
    $db_latest_view $row["Latest_View"];
        
        
            
    //Welcome user by name.
            
    echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

            <?php
            
    //Display log-out link.
            
    echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
        
            <?php 
            
    //Display User Bio.
            
    echo "<br><b>Bio:</b><br>";
            echo 
    "$db_bio";?><br>
            <br>
            
            <?php 
            
    //Display User's Latest View.
            
    echo "<br><b>Latest View:</b><br>";
            echo 
    "$db_latest_view";?><br>
            <br>

            <?php 
            
    //Display User's Latest Viewed Url in iFrame.?>
            <iframe src='<?php echo $db_latest_view;?>'></iframe>
            <?php             
        
    }
    }
    ?>

    </body>
    </html>

  4. #4
    Join Date
    Oct 2016
    Posts
    109
    Ok, I changed to single quote and the error gone but still the iframe is not opening to the url (variable value).
    Following not working:

    <?php
    //Display User's Latest Viewed Url in iFrame.?>
    <iframe src='<?php echo $db_latest_view;?>'></iframe>

    Latest code:

    PHP Code:
    <html>
    <head>
    <title>
    <?php 
    $user?>
     Home Page
    </title>
    </head>
    <body>
    <body background=".png">

    <?php
    session_start
    ();
    require 
    "conn.php";

    /*Check if user is logged-in or not by checking if session is set or not. 
    If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

    if(!isset($_SESSION["user"])) 
    {
        
    header("location:login.php");
    }
    else 
    {
        
    $user $_SESSION["user"];
        
    $sql "SELECT * FROM $user WHERE Username = '".$user."'";
        
    $result $conn->query($sql);
        while(
    $row mysqli_fetch_assoc($result))
        {
            
    $db_id $row["Id"];
            
    $db_username $row["Username"];
            
    $db_forename $row["Forename"];
            
    $db_surname $row["Surname"];
            
    $db_email $row["Email"];
            
    $db_bio $row["Bio"];
            
    $db_status_to_friends $row["Status_To_Friends"];
            
    $db_status_to_public $row["Status_To_Public"];
            
    $db_latest_view $row["Latest_View"];    
        
            
    //Welcome user by name.
            
    echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

            <?php
            
    //Display log-out link.
            
    echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
        
            <form method="post" action="">    
            <div class="form-group">
            <center><label>Post Status To Friends:</label>
            <input type="text" placeholder="Post Status To Friends" name="post_status_to_friends" /></center><br>
            <center><button type="submit" class="btn btn-default" name="post_status_to_friends" />Post Status To Friends!</button></center>
            </div>
            </form><br>
            <br>
            <form method="post" action="">
            <div class="form-group">
            <center><label>Post Status To Public:</label>
            <input type="text" placeholder="Post Status To Public" name="post_status_to_public" /></center><br>
            <center><button type="submit" class="btn btn-default" name="post_status_to_public" />Post Status To Public!</button></center>
            </div>
            </form>
            <?php
            
    //Post User Status To Friends in $user table.
            
            
    if  (isset($_POST['post_status_to_friends']))
            {
                
    $status_to_friends trim($_POST["post_status_to_friends"]);
                
    $status_to_friends mysqli_real_escape_string($conn,$status_to_friends);
            
                
    $sql "UPDATE $user SET Status_To_Friends = '$db_status_to_friends' WHERE Username = '".$user."'";
                if(
    $conn->query($sql)===TRUE)
                {
                    echo 
    "posted status for friends to $user table!";
                }
                else    
                {
                    echo 
    "posting status for friends to $user table failed!";
                }
        
                
    //Post User Status To Friends in "users" table.
            
                
    $sql "UPDATE users SET Status_To_Friends = '$db_status_to_friends' WHERE Username = '".$user."'";
                if(
    $conn->query($sql)===TRUE)
                {
                    echo 
    "posted status for friends to users table!";
                }
                else    
                {
                    echo 
    "posting status for friends to users table failed!";
                }
            }
            
    ?><br>
            <br>
                
            <?php
            
    //Post User Status To Public in $user table.
        
            
    if  (isset($_POST['post_status_to_public']))
            {
                
    $status_to_public trim($_POST["post_status_to_public"]);
                
    $status_to_public mysqli_real_escape_string($conn,$status_to_public);
            
                
    $sql "UPDATE $user SET Status_To_Public = '$db_status_to_public' WHERE Username = '".$user."'";
                if(
    $conn->query($sql)===TRUE)
                {
                    echo 
    "posted status for public to $user table!";
                }
                else    
                {
                    echo 
    "posting status for public to $user table failed!";
                }
        
                
    //Post User Status To Public in users table.
                
    $sql "UPDATE users SET Status_To_Public = '$db_status_to_public' WHERE Username = '".$user."'";
                if(
    $conn->query($sql)===TRUE)
                {
                    echo 
    "posted status for public to users table!";
                }
                else    
                {
                    echo 
    "posting status for public to users table failed!";
                }                
            }
            
    ?><br>
            <br>
                
        <?php 
        
    //Display User Status To Friends. Search for User's data with $user.
                
        
    $query "SELECT * FROM $user WHERE Username = '".$user."'";
        
    $result mysqli_query($conn,$query);
        
    $numrows mysqli_num_rows($result);
        if(
    $numrows 0)
        {        
            echo 
    "No data!";
        }
        else 
        {
            while(
    $row mysqli_fetch_assoc($result)) 
            {      
                
    $db_status_to_friends $row["Status_To_Friends"];
            }
            echo 
    "<br><b>$user Status To Friends:</b><br>
            
    $db_status_to_friends";
            }
        }
        
    ?><br>
        <br>
            
        <?php 
        
    //Display User Status To Public. Search for User's data with $user.
        
    $query "SELECT * FROM $user WHERE Username = '".$user."'";
        
    $result mysqli_query($conn,$query);
        
    $numrows mysqli_num_rows($result);
        if(
    $numrows 0)
        {        
            echo 
    "No data!";
        }
        else 
        {
            while(
    $row mysqli_fetch_assoc($result)) 
            {      
                
    $db_status_to_public $row["Status_To_Public"];
            }
            echo 
    "<br><b>$user Status To Public:</b><br>
            
    $db_status_to_public";
        }
        
    ?><br>
        <br>
                
        <?php 
        
    //Display User's Latest View.
        
    echo "<br><b>Latest View:</b><br>";
        echo 
    "$db_latest_view";?><br>
        <br>

        <?php 
        
    //Display User's Latest Viewed Url in iFrame.?>
        <iframe src='<?php echo $db_latest_view;?>'></iframe>
        
        <?php 
        
    //Display User Bio.
        
    echo "<br><b>Bio:</b><br>";
        echo 
    "$db_bio";?><br>
        <br>
        
        <?php 
    }

    ?>

    </body>
    </html>

  5. #5
    Join Date
    Oct 2016
    Posts
    109
    Hi,

    Tried all that but no luck as iframe not showing any page on my google chrome.
    Tried now (notice the single &amp; double quotes):
    <?php
    //Display User's Latest Viewed Url in iFrame.?>
    <iframe src='<?php echo $db_latest_view;?>'></iframe>
    <br>
    <iframe src="http://www.google.com"></iframe>
    <br>
    <iframe src='http://www.google.com'></iframe>
    <br>

    [/php]

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,928
    Pro tip: Code a little bit at a time. Make sure it works.* Then code a little bit more. Repeat until done.
    ________________
    * E.g., use var_export() and/or error_log() and/or die() to look at variables and such to see if you got the expected results before you try to use those results.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles