Hi,
I'am new to PHP but i'am currently doing the project in PHP only,i want to use function return values in another form,the return value is a value retrieved from MYSQL,just see my code
------------------------------------------------
form1//where i calling my function

selecttbl("user");
while($row=mysql_fetch_array($result))   
{
    for ($i=0; $i<mysql_num_fields($result); $i++)
    echo $row[$i] . " ";
}

--------------------------------------------------
form2 where i have to return the retrieved values to form1

function selecttbl($tblname)
{
$result = mysql_query ("SELECT * FROM $tblname");
return $result;
}

----------------------------------------------------

just help me out

You have to assign the return value to a variable before using it.
ie., $result = selecttbl("user");

oh assuming your code is working the only line you need to fix is:

selecttbl("user");
// CHANGE TO 
$result = selecttbl("user");

Hi,
still i'am getting error,i'll mention the error below

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\org09\demo.php on line 4

demo.php
---------------------------------------------------------------------

<?php
include("db.php");
$result=selecttbl("user");
while($row=mysql_fetch_array($result))   
{
    for ($i=0; $i<mysql_num_fields($result); $i++)
	{
    echo $row[$i] . " ";
	}
}
?>

db.php
---------------------------------------------------------------------------

<?php

$connection=mysql_connect("localhost", "root", "");
mysql_select_db("org");
function selecttbl($tblname)
{
$result = mysql_query ("SELECT * FROM $tblname,$connection");
return $result;
echo $tblname;
}	

mysql_close($connection);	

?>

Hi,
I'am new to PHP but i'am currently doing the project in PHP only,i want to use function return values in another form,the return value is a value retrieved from MYSQL,just see my code
------------------------------------------------
form1//where i calling my function
selecttbl("user");
while($row=mysql_fetch_array($result))
{
for ($i=0; $i<mysql_num_fields($result); $i++)
echo $row[$i] . " ";
}

--------------------------------------------------
form2 where i have to return the retrieved values to form1
function selecttbl($tblname)
{
$result = mysql_query ("SELECT * FROM $tblname");
return $result;
}
----------------------------------------------------

just help me out

$result = mysql_query ("SELECT * FROM $tblname,$connection");

is wrong. Use

$result = mysql_query ("SELECT * FROM $tblname");

:) And please use tags next time to wrap your code.[code=php ] tags next time to wrap your code.

Hi,
Thanks for your immediate reply,now i got the value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.