Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How To Display Data in iFrame A Url From Mysql?

    • 0
    • 0
    • 0
    • 3
    • 0
    • 0
    • 0
    • 1.46k
    Answer it

    This is my latest shortened version of the homepage in my reg-login site PHP.
    When you login to your account, your homepage welcomes you with your first & surname.
    Then it is supposed to show you your bio ($row "bio" in tbl) and show you an url in an iframe ($row "your website" in tbl).

    Problem is, the iframe is not showing the data (url) that is in the  "your website" in tbl.
    I tried escaping, switching to a single quote from double but no luck.
    What do you think is wrong?

    [php]
    
    <html>
    <head>
    <title>
    $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.php.*/
    
    if(!isset($_SESSION["user"])) 
    {
        header("location:login.php");
    }
    else 
    {
        $user = $_SESSION["user"];
        $sql = "SELECT * FROM users 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_your_fav_url = $row["Fav_Url"];
        
        
            //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>
            $db_bio";?><br>
            <br>
            
            <?php 
            //Display User's Fav Url in iFrame.?>
            <iframe src='$db_your_fav_url'></iframe>
            <?php             
        }
    }
    ?>
    
    </body>
    </html>
    
    [/php]

    The "Bio" column shows no data on the page even though the column contains data in the db.
    I get error:

    [16-Mar-2017 15:29:44 UTC] PHP Notice:  Undefined index: Your_Fav_Url in /home/sn/public_html/sn/home.php on line 34
     

 3 Answer(s)

  • You did the syntax mistake on line 69. Kindly write the below line.
     
    $sql = "UPDATE $user SET Status_To_Friends = '" . $db_status_to_friends . "' WHERE Username = '".$user."'";

    Thank you
  • My update

    [php]
    <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>
    [/php]


    I get error:

    PHP Parse error:  syntax error, unexpected '$db_status_to_friends' (T_VARIABLE) in .... on line 69.

    How can it be unexpected variable on line 69 since I declare it on line 35 ?
  • Hello Sir,

    I just go through your mentioned code. I found some mistakes. In title tag your are using variable $user which does not contain anything. If you are fetching data from database then you can test the fetched data using echo statement. You need to give the width and height to your iframe.

    Hope this help!

    Thank You
    Deepak Verma
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: