Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How To Display In iFrame A Url From Mysql ?

php

  • Please log in to reply
6 replies to this topic

#1 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 16 March 2017 - 07:38 AM

This is my latest shortened version of the homepage in my reg-login site php.
When you login to your account, your homepage welcomes yuo with your first & surname.
Then it is supposed to show you your bio ($row "bio" in tbl) and show you a 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 single quote from double but no luck.
What do you think is wrong ?
 
 
<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>
 
 
The "Bio" column shows no data on page even thopugh 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
 

  • 0

#2 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 17 March 2017 - 05:50 PM

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!
 
 
<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>
 

  • 0

#3 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 19 March 2017 - 03:56 AM

This forum is no good and dead!


  • 0

#4 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 29 April 2017 - 04:56 PM

Hi,

Imagine there is a tbl called "users" and it has a column called "your blog url".
Now, imagine you want to display that blog's url in an iframe on one of your pages. How would you code it ?
I did the following but the iframe fails to load the webpage.
I guess this is due to me failing to get the iframe to pic one url or one entry from the "your blog url" column.

The best attempt I made was this:

<?php 
    //Display User's blog?>
    <iframe src="<?php $row["blog"];?>"></iframe>
​​​​​​​

How would you code it yourself ? Imagine, you want to display in the iframe the url that is the final entry in the "your blog url" column in users tbl in mysql db.

Imagine the tbl looks like this:

     users
id|your_blog_url
6|http://myownblog.com

And since the "http://myownblog.com" is the final entry in the "your_blog_url" column you want to load that in the iframe.

Whatever sample you provide, make sure it works by checking it in your wamp/xampp before adding your code in this thread.

Thanks!
 
  • 0

#5 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 01 May 2017 - 05:56 AM

Ok,
 
Here's the original script.
I shortened it 2 nights ago so you guys don't have to wade through many lines of code. And while shortening it, I made mistakes. And so, here's the full script for that particular page.
config.php contains the db connection details and other files.
 
 
 
   
    <html>
    <head>
    <title>
    Home Page
    </title>
    </head>
    <body>
    
    <?php
    include 'config.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 users WHERE usernames = '".$user."'";
     $result = mysqli_query($conn,$sql);
        $numrows = mysqli_num_rows($result);
        if($numrows >1)
     { 
     while ($row = mysqli_fetch_assoc($sql))
     {
     $db_id = $row["id"];
     $db_username = $row["usernames"];
     $db_first_name = $row["first_names"];
     $db_surname = $row["surnames"];
     $db_email = $row["emails"];
     $db_blog_url = $row["blogs_urls"];
        
         //Welcome user by name.
     echo "Welcome <b><h2>$db_first_name $db_surname!"?></h2></b>|
    
     <?php
     //Display log-out link.
     echo "<a href='logout.php'>$user Log Out</a>";?>|<br>
        
     <?php 
     //Display User's own blog Page in iframe.?>
     <iframe src="<?php echo $db_blog_url;?>"></iframe>
     <br>
    
     <?php 
     //Display 1st User's blog Page (regardless of who the user is) in iframe.?>
     <iframe src="<?php echo ".$blogs_urls[0].";?>"></iframe>
     
     <?php 
     //Display All Users' blogs Pages in iframe.?>
     <iframe src="<?php echo $row['blogs_urls'];?>"></iframe>
     <?php 
     }
        } 
    }
    ?>
    
    </body>
    </html>
   
   
   
Ignore the part where my code is not secure from sql injection. I will deal with that later. In the meanwwhile, concentrating on how to fix this frame thing. I attempted 3 different ways to code the iframe to load a webpage but no luck. I don't get any errors but a complete blank page. (Error settings is full set to show error messages).

  • 0

#6 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 01 May 2017 - 06:16 AM

Error settings is full set to show error messages (config.php):
 
/*
* ERROR HANDLING
* ini_set('display_errors', 1);
*   ini_set('display_startup_errors', 1);
 
* For All Error, Warning and Notice
*   error_reporting(E_ALL); OR error_reporting(-1);
* For All Errors
*   error_reporting(E_ERROR);
* For All Warnings
*   error_reporting(E_WARNING);
* For All Notice
*   error_reporting(E_NOTICE);
*/
error_reporting(E_ALL);

  • 0

#7 uniqueideaman

uniqueideaman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 52 posts

Posted 06 May 2017 - 05:35 AM

Man,

Atleast one url should load properly in my inframe since not every website in the world would not be putting measures to foil iframes. 
How-about you try loading a page and when it works then give me the url to check out on my end.

I've now taken out all the session code altogether.
Code now looks like this:

<html>
<head>
<title>
Home Page
</title>
</head>
<body>
<body background=".png">

<?php
include 'config.php';

    $sql = "SELECT * FROM users WHERE usernames = 'USERNAME WENT HERE'";
    $result = mysqli_query($conn,$sql);
    $numrows = mysqli_num_rows($result);
    if($numrows >0)
    {    
        while ($row = mysqli_fetch_assoc($result))
        {
            $db_id = $row["ids"];
            $db_username = $row["usernames"];
            $db_first_name = $row["first_names"];
            $db_surname = $row["surnames"];
            $db_email = $row["emails"];
            $db_blog_url = $row["blogs_urls"];
    
            //Welcome user by name.
            echo "Welcome <b><h2>$db_first_name $db_surname!"?></h2></b>|

            <?php 
            //Display User's own blog Page in iframe.?>
            <iframe src='<?php echo $row["blog_urls"];?>'></iframe>
            <br>

            <?php 
            //Display 1st User's blog Page (regardless of who the user is) in iframe.?>
            <iframe src="<?php echo '.$blogs_urls[0].';?>"></iframe>
                
            <?php 
            //Display 1st User's blog Page (regardless of who the user is) in iframe.?>
            <iframe src='<?php echo ".$blogs_urls[0].";?>'></iframe>
            <?php 
            
        }
    }
    else
    {
    echo "<p>No Results!</p>\n" ;
    }    
?>

</body>
</html>

I have changed the url from my db to:

http://www.goviralno...iques-for-2017/

But I don't see any pages loading. I picked a page most likely to be unknown. However, now see no blank page but 3 iframes with 3 error messages:

1st error message:

**Access forbidden!**

**You don't have permission to access the requested object. It is either read-protected or not readable by the server.**

**If you think this is a server error, please contact the webmaster.**

**Error 403**

**localhost**
**Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9**


2nd error message:

**Object not found!**

**The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.**

**If you think this is a server error, please contact the webmaster.**

**Error 404**

**localhost**
**Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9**


3rd error message:

Same as 1st error message.

Note from my most recent code, I have 3 iframes coding 3 different ways with php. Looking at these error messages and my 3 iframe codes, what is your conclusion ? What do you make out of all this ?

Edited by uniqueideaman, 06 May 2017 - 05:49 AM.

  • 0