gareth
gareth

Reputation: 189

php mysql connection does not show results why

this is driving me crazy why aren't the results showing???

function runSQL($rsql) {

    $connect = mysql_connect('localhost','xxx','xxx') or die ("Error: could not connect to database");
    $db = mysql_select_db('xxx');

    $result = mysql_query($rsql) or die ("Error in query: $query. " . mysql_error());

    return $result;
    mysql_close($connect);
}

$rsql = "SELECT * FROM subscriptions WHERE subscriptionID = 6 ";
runSQL($rsql);
$row = mysql_fetch_array($result);
echo $row['subscription'];
mysql_free_result($result);

Upvotes: 1

Views: 154

Answers (2)

MightyE
MightyE

Reputation: 2679

If you close the connection before doing mysql_fetch_(assoc|array|etc) on it, those functions will likely fail. The connection should not be closed until you're done interacting with the database, including reading the data.

Upvotes: 0

Select0r
Select0r

Reputation: 12628

You don't process your result ...

You call your function (runSQL) to execute the query and it returns the resultset, but you don't catch the resultset to work with it.

Use $result = runSQL($rsql); instead of runSQL($rsql);.

Also note that mysql_close($connect); is never called in your code, it's unreachable as the return occurs first.

Upvotes: 3

Related Questions