MrTV
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.8 2', '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);
<?php
error_reporting(E_ALL);
$link = mysql_connect('192.168.0.8
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>");
}
}
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_n ame');
$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_n
$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. :)