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:
[code]
<?php
//Display User's blog?>
<iframe src="<?php $row["blog"];?>"></iframe>
[/code]
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.
Watch your syntax also. The code you posted has four double quotes which could be confusing and sometimes will be interpreted as two sets of open/close quotes. It would be clearer if you wrote $row ['blog'] with single quotes. And should there not be an echo just in front of that?
There is nothing wrong with the syntax though. The first pair of quotes belong to HTML and the second to PHP. Nowere it can be interpreted as two sets of open/close quotes.
These asterisks turn up out of the blue when I copy and paste code from my note pad++.
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 which you see in my previous code. And so, here’s the full script for that particular page.
config.php contains the db connection details and other files.
I get no erros but I get nothing visible on the screen. Full blank white page!!!
[code]
<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>
[/code]
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 (config.php):
I tried displaying a couple of URLs inside an iframe and not all rendered. A Google search recommended using file_get_contents(); inside a div and another to use curl();.
Did you remember that the problem you were having with your prepared statement in another thread was that you had changed the column name in your table, and one of the ones you specifically mentioned was that you’d changed usernames to username.
Would that explain why none of the previous echo outputs were appearing and giving the OP:
This line, however
header("location:login.php");
is pointless as it comes after some output to the browser, in the shape of the html prior to the php code, and therefore will just give “headers already sent”. The same might apply to the session_start() code, wherever that is.
Thanks for pointing this out but I spotted this error by myself just 2 mins before reading your post. But still, thanks for remembering my old threads and the problems I had and for pointing this silly mistake of mine again.
Shall I tell you what else, I spotted ? I changed the code a little and got error which pointed me to realizing I had written “$sql” instead of “$result”.
Mistaken code was ..
if($numrows >1)
{
while ($row = mysqli_fetch_assoc($sql))
{
Supposed to be:
if($numrows >0)
{
while ($row = mysqli_fetch_assoc($result))
{
Everyone here, overlooked that. Didn’t you all ? Lol!