So I have a script that retrieves an image from a sql table and displays it.
I can call the script inside a html using something like this:

<img src="display01.php"/>

Now I have another script called "text01.php" that fetches text from the sql table and the script works 100%; what I need is how to call that script inside the html.

Here is the code:

<html>
  <body>
  ....
  ....
    
    <div class="nice">
      <div style="position:absolute; top:50px; left:60px;">
        <img src="display01.php"/>
      </div>
      <div style="position:absolute; top: 100px; left: 400px;">
        <!--text01.php should go here-->
      </div>
    </div>
   </body>
</html>

text01.php:

<?php
   //variables that will be needed to connect to mysql
  $host="localhost";
  $username="root";
  $password="quatre";
  $database="binary";
  //make connection to mysql
  //and store connection in the variale $con
  $con=mysql_connect($host,$username,$password);
  //die if it didn't connect
  if(!$con)
  {
  die('Could not connect'. mysqlerror());
  }
  //if connected
  //select database to use
  mysql_select_db($database);
  //store query in variable $query
  $query="SELECT description from tbl_images where id=1";
  $results=mysql_query($query,$con);
  $row = mysql_fetch_array($results);
  echo $row['description'];
?>

How can I call the second script?

Member Avatar for diafol
<?php include('text01.php');?>
<?php include('text01.php');?>

This is exactly not working at the moment and I can't understand why and even when I changed the page to .php extension.

Actually I am badly stucj since to display the text from the database I need to save the html page as .php so that this works

<?php include('text01.php');?>

Now I have another problem the page from which I am calling "text01.php" is being used in a link in another page.

Here are the codes:

<html>
<head>
<title>Buy Macs</title>
<link rel="shortcut icon" type="image/ico" href=favicon.ico mce_ref=favicon.icon>
<link rel="stylesheet" href="format.css" type="text/css" />
</head>
<body marginheight= "10" marginwidth="20" topmargin="10" leftmargin="20">
<h2 class="italia">Apple eStore Mauritius</h2>
<div style="position: absolute; left: 200px;">
<h2>Shop Mac</h2>
</div>
<div id="sub1">A computer unlike any other.Easy to use, powerful, compatible and 

secure</div>
<div id="side1"><a href="index.html">Home</a></div>
<div id="side2"><a href="ipods.html">iPods</a></div>
<div id="side3"><a href="iphones.html">iPhones</a></div>
<div id="side4"><a href="http://www.apple.com/">Apple.com</a></div>
<div id="side5"><a href="support.html">Support & Policy</a></div>
<div style="width:500px; border: gray thin solid; position: absolute; top: 110px; left: 

200px; font-weight: bold; background-color: #4682B4;">
&nbsp;Mac Family
</div>
<div style="border:gray thin solid; position:absolute; top:130px; left:200px; width:500px; 

height:530px;"> 
</div>
 <div id="macpic1">
    <a href="macbook.php"><img src="product-white-hero2.jpg" alt="MacBook pic"/></a>
    <br/>
    <a class="nav" href="macbook.php">MacBook</a>
 </div>
 <div id="macpic2">
    <a href="macbookpro.html"><img src="product-front-13.jpg" alt="MacBook Pro pic"/></a>
    <br/>
    <a class="nav" href="macbookpro.html">MacBook Pro</a>
 </div>
 <div id="macpic3">
    <a href="macbookair.html"><img src="product-air.jpg" alt="Macbook Air pic"/></a>
    <br/>
    <a class="nav" href="macbookair.html">MacBook Air</a>
 </div>
 <div id="macpic4">
    <a href="macmini.html"><img src="product-front-mini.jpg" alt="Macmini pic"/></a>
    <br/>
    <a class="nav" href="macmini.html">Macmini</a>
 </div>
 <div id="macpic5">
    <a href="iMac.html"><img src="product-27in.jpg" alt="iMac pic"/></a>
    <br/>
    <a class="nav" href="iMac.html">iMac</a>
 </div>
 <div id="macpic6">
    <a href="macpro.html"><img src="product-front-side.jpg" alt="Mac Pro pic"/></a>
    <br/>
    <a class="nav" href="macpro.html">Mac Pro</a>
 </div>
</body>
</html>

Macbook.php:

<html>
  <head>
    <title>Macbook-Apple Store Mauritius</title>
    <link rel="shortcut icon" type="image/ico" href=favicon.ico mce_ref=favicon.icon>
    <link rel="stylesheet" href="format.css" type="text/css" />
  </head>
  <body>
    <h2 class="italia">Apple eStore Mauritius</h2>
    <div id="side1"><a href="index.html">Home</a></div>
    <div id="side2"><a href="ipods.html">iPods</a></div>
    <div id="side3"><a href="iphones.html">iPhones</a></div>
    <div id="side4"><a href="http://www.apple.com/">Apple.com</a></div>
    <div id="side5"><a href="support.html">Support & Policy</a></div>
    <div class="nice">
      <div style="position:absolute; top:50px; left:60px;">
        <img src="display01.php"/>
      </div>
      <div style="position:absolute; top: 100px; left: 400px;">
        <?php include('text01.php');?>
      </div>
    </div>
   </body>
</html>

So I changed macbook.html to macbook.php but on the macs page when I click on the macbook link it goes to macbook.html and not macbook.php even if there is no macbook.html that exist and it never shows the text that needs to be displayed using this

<?php include('text01.php');?>

I think its because of this portion:

<a href="macbook.php"><img src="product-white-hero2.jpg" alt="MacBook pic"/></a>
    <br/>
    <a class="nav" href="macbook.php">MacBook</a>

since I am trying to use .php as a link.

Can someone please help me I am badly stuck

Member Avatar for diafol

You can't use php in .html/.htm unless you specify that in Apache or you use a templating engine which 'caches' your html file as php. Just use .php extensions - it saves a lot of hassle.

With regard to your problem:

1) Change all your html/htm extensions to php.
2) Do a find/replace for ".html" to ".php" in your pages. Do one at a time in case you have external links that actually do have a html/htm extension.

This may sound a drastic move, but messing around with html/htm when you've got a heavy implementation of php is asking for trouble.
html/htm files should only have js/xhtml/styling etc.

You can't use php in .html/.htm unless you specify that in Apache or you use a templating engine which 'caches' your html file as php. Just use .php extensions - it saves a lot of hassle.

So if I change everything in my project to .php it should work perfectly?

You can't use php in .html/.htm unless you specify that in Apache or you use a templating engine which 'caches' your html file as php. Just use .php extensions - it saves a lot of hassle.

With regard to your problem:

1) Change all your html/htm extensions to php.
2) Do a find/replace for ".html" to ".php" in your pages. Do one at a time in case you have external links that actually do have a html/htm extension.

This may sound a drastic move, but messing around with html/htm when you've got a heavy implementation of php is asking for trouble.
html/htm files should only have js/xhtml/styling etc.

Okay I got it!

SO i CHANGED EVERYTHING TO .php and its really saved as .php and all my links modified to .php but now when I go to phpmyadmin and to the folder that contains my project it displays the index page with everything that's on it working but when I click on a link for example when I click on the Macs link that is supposed to go to macs.php it gives me this error:

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.
Error 404
127.0.0.1
12/28/09 17:27:46
Apache/2.2.13 (Win32) PHP/5.3.0

That's the url it is going to:
http://127.0.0.1/Web%20Project%20-%20Copy/Macs.html when there really is no .html file remaining.

And if I just open the index.php(not through phpmyadmin) it shows the index page and when I click on the macs link it does go to
file:///C:/Program%20Files/EasyPHP5.3.0/www/Web%20Project%20-%20Copy/Macs.php

What's wrong now?

Member Avatar for diafol

I don't understand why you're going through phpmyadmin.

Show the code for the link that you're pressing (you can get to it from 'view source' in the browser).

So I come back after a coffee break and try again and guess what.
Suddenly everything is working fine just as I wanted.
Thanks a lot for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.