[SOLVED] database problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
arong
Forum Newbie
Posts: 7
Joined: Tue Apr 19, 2005 9:57 am

[SOLVED] database problem

Post by arong »

hi, I hope someone can help me with this,
I have installed php 5, Sql server and apache all well configured.

I´m new to php programing, so now i´m only trying to connect
to a database, extract files from it and display them.

I have made a simple script to do that but the IE returns nothing,
it displays a blank page, not even an error, all is well configured
and I have tested that.

this is my script:

Code: Select all

<?php
$myServer = "06-sistemas";
$myUser = "sa";
$myPass = "password";
$myDB = "nueva";

$s = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");

$d = mssql_select_db($myDB, $s)
or die("Couldn't open database $myDB");

$query = "select * from tabla1";
      $result = mssql_query($query);

while($tmp = mssql_fetch_array($result)) {

              print $tpm["nombre"];
              print "<br>";
              print $tpm["edad"];
              print "<br>";

                   }
      mssql_close($s);

?>
thanks in advanced
Arong


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check your php.ini to make sure error_reporting is set to E_ALL only, and display_errors is on.

Next, if the sql server is on the web server, try using 'localhost'
arong
Forum Newbie
Posts: 7
Joined: Tue Apr 19, 2005 9:57 am

Post by arong »

Thanks for your replay,

It does not appear any error after doing that, however I realised that
It does extract the data from the database, it is there, but it is invisible
I don´t know why.

I realised that because I added this: (echo ¨hi¨;) at the end of the script
and It appeared at the middle of the page, then I added more data to the database and the hi text appeared but down.

I changed the color of the page but without luck.

any idea
arong
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

arong wrote:Thanks for your replay,

It does not appear any error after doing that, however I realised that
It does extract the data from the database, it is there, but it is invisible
I don´t know why.

I realised that because I added this: (echo ¨hi¨;) at the end of the script
and It appeared at the middle of the page, then I added more data to the database and the hi text appeared but down.

I changed the color of the page but without luck.

any idea
arong
the $tpm['edad'] and $tpm['nombre'] variables are probably empty, or non-existant. Check your table structure and contents, you mayb be missing something ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have any other code on this script/page? It likely means you got something goofy in your output page code.. or you are accidentally writing this stuff into an "invisible" div or similar.
arong
Forum Newbie
Posts: 7
Joined: Tue Apr 19, 2005 9:57 am

Post by arong »

thanks again for your replays, I´m still stuck.

the whole code is that I already posted,

I´ll keep looking the couse of the error on the web , I have almost proved everything.

Arong
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you notice that $tpm is not $tmp ? :P

You don't have error_reporting turned on to E_ALL.. :)
arong
Forum Newbie
Posts: 7
Joined: Tue Apr 19, 2005 9:57 am

Post by arong »

:roll:

thank you, everything is working fine now, that stupid mistake almost killed me.

:) :) :) :)

I know I´ll have more questions cause Im new to php.
Arong
Post Reply