Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

newbie problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

newbie problem

Postby dpetric » Thu Nov 22, 2012 1:10 pm

Hi i have problem with following code

Code: Select all
 <html>
   <head>
   </head>
   <body>
      <?php
       mysql_connect("localhost", "root", "eucenje") or die(mysql_error());
       mysql_select_db("conquer_the_world") or die(mysql_error());
      
       $data = mysql_query("SELECT * FROM country") or die(mysql_error());
       Print "<table border='1'>";
      
       while($info = mysql_fetch_array( $data )) {
          Print "<tr>";
          Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
          Print "<th>Pet:</th> <td>".$info['idCountry'] . " </td></tr>";
       }
       Print "</table>";
       ?>
   </body>
</html>


The output in browser comes:
"; while($info = mysql_fetch_array( $data )) { Print ""; Print "Name: ".$info['name'] . " "; Print "Pet: ".$info['idCountry'] . " "; } Print ""; ?>

I think the problem is that first ">" from table closes php badge
dpetric
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Nov 22, 2012 12:47 pm

Re: newbie problem

Postby simplypixie » Thu Nov 22, 2012 11:42 pm

All your Print references should be echo
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: newbie problem

Postby dpetric » Fri Nov 23, 2012 12:48 am

simplypixie wrote:All your Print references should be echo



i did that but still same thing

output is now:

"; while($info = mysql_fetch_array( $data )) { echo ""; echo "Name: ".$info['name'] . " "; echo "Pet: ".$info['idCountry'] . " "; } echo ""; ?>
dpetric
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Nov 22, 2012 12:47 pm

Re: newbie problem

Postby simplypixie » Fri Nov 23, 2012 3:29 am

So your code now looks like this
Code: Select all
<html>
   <head>
   </head>
   <body>
      <?php
       mysql_connect("localhost", "root", "eucenje") or die(mysql_error());
       mysql_select_db("conquer_the_world") or die(mysql_error());
       
       $data = mysql_query("SELECT * FROM country") or die(mysql_error());
       echo "<table border='1'>";
       
       while($info = mysql_fetch_array( $data )) {
          echo "<tr>";
          echo "<th>Name:</th> <td>".$info['name'] . "</td> ";
          echo "<th>Pet:</th> <td>".$info['idCountry'] . " </td></tr>";
       }
       echo "</table>";
       ?>
   </body>
</html>


And you are still getting the while loop php printing in the browser? That doesn't make any sense as there is nothing wrong with this code.
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: newbie problem

Postby dpetric » Sat Nov 24, 2012 12:59 am

yes that's how my code looks.
dpetric
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Nov 22, 2012 12:47 pm

Re: newbie problem

Postby simplypixie » Sat Nov 24, 2012 1:55 am

That code should not be printing out your php code. Is your file definitely a .php not .html? Is there anything else on the page that you aren't showing?
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: newbie problem

Postby dpetric » Sun Nov 25, 2012 1:22 pm

solved :D

i was editing default index file that had .php ending.

Tnx for all help
dpetric
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Nov 22, 2012 12:47 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.