Link to home
Start Free TrialLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

It can nonnect to database but i can not get the result

what wrong with it it can not show any result

<?php
error_reporting(E_ALL);

$link = mysql_connect('192.168.0.82', 'souser', 'sopass' , 'AOL');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';

$result = mysql_query("SELECT Code, Name, OnHand FROM  192.168.0.82.AOL.prdmas WHERE OnHand != 0)", $link;

while($row = mysql_fetch_row($result))
{
    $Code    = $row[0];
    $Name    = $row[1];
    $OnHand = $row[2];


    echo "Name :$Code<br>" .
         "Subject : $Name  <br>" .
         "Message : $OnHand <br><br>";
}


mysql_close($link);
SOLUTION
Avatar of gemdeals395
gemdeals395

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gemdeals395
gemdeals395

Has this problem just started occuring? If you have been using this function before successfully what have you changed to have it fail? Is it only failing in this particular app and not others? Try seeing if there is an sql issue with a very simple sql query like a simple  SELECT * FROM database and see if you can get the simple query to run. And once you have a function connected you should be able to do this:

$result = mysql_query("SELECT Code, Name, OnHand FROM  prdmas WHERE OnHand != 0)", db_connect());

Because once you have a successful connect then the resources of that db are available to you. :)
Or in your example:

$sql = "SELECT Code, Name, OnHand FROM  prdmas WHERE OnHand != 0";
$result = mysql_query($sql,db());
if($mysql_num_rows($result)) {
    while($row = mysql_fetch_array($result) {
        echo("Name: $row[0]<br>Subject: $row[1]<br>Message: $row[2]<br><br>");
    }
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To do the same in the original code:

$result = mysql_query("SELECT Code, Name, OnHand FROM  192.168.0.82.AOL.prdmas WHERE OnHand != 0", $link) or die(mysql_error());

And like gemdeals395 and michel-angelo already included in their wrapper functions, there should be a mysql_select_db() statement present.

So, under this line:
echo 'Connected successfully';

THere should be one like this:
mysql_select_db('your_db_name');