...

please help ....

HormonX
11-21-2002, 12:56 AM
am not sure what am doing wrong ...

am trying to get results after user input but i only need one row so i did this;



//this is my connection script that i use on all my pages
include('connect.php');
//this is my query
$query = "SELECT name FROM mytable where value='$uservalue'";
//this where i do query $link is within connect.php
$result = mysql_query($query, $link)

while($r = mysql_fetch_row($result))
{

hello my name is: $r[0]

}



i have also tried this :




//this is my connection script that i use on all my pages
include('connect.php');
//this is my query
$query = "SELECT * FROM mytable where value='$uservalue'";
//this where i do query $link is within connect.php
$result = mysql_query($query, $link)

while($r = mysql_fetch_row($result))
{

$name = $r['name'];

hello my name is: $name

}




And in both time i get this error....


Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/domain/public_html/myfile.php on line 103



Please help me... :)


HormonX

mat
11-21-2002, 09:43 AM
try to Use a more descriptive subject line next time. I think you are looking in the wrong place in terms of what is causing this error. ( 'Warning: mysql_fetch_row():' )

What exactly is '$link' ?

HormonX
11-21-2002, 03:28 PM
you are right ... i should use a more descriptive subject ....

here is how i use link ...



$user = "username";
$pass = "password";
$db = "db_name";
$link = mysql_pconnect("localhost", $user, $pass);
if ( ! $link )
die( " Can not connect to MySQL database");
mysql_select_db( $db )
or die ("Can not open database: ".mysql_error() );



so would you have any ide why am getting this error message ?

HormonX

firepages
11-21-2002, 04:14 PM
if you are using $link here...


<?
$link = mysql_pconnect("localhost", $user, $pass);
?>
then I am pretty sure you need to use it here as well
<?
mysql_select_db( $db , $link )
?>

but regardless unless you expect to be accessing more than 1 database in your script just drop the connection identifier completely, i.e.


<?
$user = "username";
$pass = "password";
$db = "db_name";
mysql_connect("localhost", $user, $pass) or die( " Can not connect to MySQL database");
mysql_select_db( $db )
or die ("Can not open database: ".mysql_error() );
?>


then ..


<?
include('connect.php');
$query = "SELECT name FROM mytable where value='$uservalue'";
$result = mysql_query($query);
while($r = mysql_fetch_row($result))
{
echo 'hello my name is: '.$r[0].'<br />';
}

?>

HormonX
11-21-2002, 05:10 PM
thanx for all your help :) .. but it was my mistake that i made while writing it on my computer... i wrote everything ok on the forum here .. but made an error on my computer :)

instead of



while($r=mysql_fetch_row($result))



i have put



while($r=mysql_fetch_row($query))



i can't belive am so blind :)

thanx again .. and sorry for all the trouble :)

HormonX

Spookster
11-21-2002, 05:30 PM
On another note in the future you need to use a proper subject line for threads. "Please help" is not a proper subject line. Read the Posting guidelines.

Also this should have been posted in the MySQL forum as stated by the Must Read thread at the top of the PHP forum and by the MySQL forum description.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum