Jump to content

MySQL_Close error


u0206787@nus.edu.sg

Recommended Posts

[code]
$connect = mysql_connect($host, $user, $password);
if (!$connect) {
   die('Not connected : ' . mysql_error());
}
$db=mysql_select_db($database, $connect);
if (!$db) {
   die ('Can\'t use $database: ' . mysql_error());
}
mysql_close($connect);
[/code]
Pls find what wrong with the code, I keep receive these errors.

These are the two error I received.
1. Undefined variable: connect

2. Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in c:\program files\easyphp1-8\www\test\login.php on line 86

Cheers.

Link to comment
Share on other sites

you should have to put
[code]$db=mysql_select_db($database, $connect);[/code]
you can just put:
[code]mysql_select_db($database, $connect);[/code]

and when using mysql_close you dont have to specify the link identifier. it can simply be:
[code]mysql_close();[/code]
and it will close the last open connection.
Link to comment
Share on other sites

[quote author=ProjectFear link=topic=109943.msg443614#msg443614 date=1159529620]
you should have to put
[code]$db=mysql_select_db($database, $connect);[/code]
you can just put:
[code]mysql_select_db($database, $connect);[/code]

and when using mysql_close you dont have to specify the link identifier. it can simply be:
[code]mysql_close();[/code]
and it will close the last open connection.
[/quote]

Thanks, however this time it showing another error. This time, it's showing:
"Warning: mysql_close(): no MySQL-Link resource supplied ".
I'm running on EasyPHP 1.8.0.1; with Apache 1.3.33; PHP 4.3.10; MySQL 4.1.9.
Link to comment
Share on other sites

[code]
<?php
if (isset($signin) && !empty($signin)) {

$connect = mysql_connect($host, $user, $password);
if (!$connect) {
  die('Not connected : ' . mysql_error());
}

$db=mysql_select_db($database, $connect);
if (!$db) {
  die ('Can\'t use $database: ' . mysql_error());
}

$result = mysql_query("SELECT * FROM Registration where studentid = '$studentid' and password='$pwd'")
or die(mysql_error());

mysql_close();
[/code]

Can anyone help me Pls?
"Warning: mysql_close(): no MySQL-Link resource supplied ".
I'm running on EasyPHP 1.8.0.1; with Apache 1.3.33; PHP 4.3.10; MySQL 4.1.9.
Link to comment
Share on other sites

[quote author=Gaoshan link=topic=109943.msg444106#msg444106 date=1159593097]
[code]mysql_close($connect)[/code]
[/quote]
when I use "mysql_close($connect);" it give me 2 errors as below.
1. Notice: Undefined variable:
2. Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in

however if I were to use "mysql_close();" it gave me an error as:
1. Warning: mysql_close(): no MySQL-Link resource supplied .

What wrong with this quote?
Link to comment
Share on other sites

[code]
if (isset($adminsignin) && !empty($adminsignin)) {
$connect = mysql_connect($host, $user, $password);
if (!$connect) {
  die('Not connected : ' . mysql_error());
}
$db=mysql_select_db($database, $connect);
if (!$db) {
  die ('Can\'t use $database: ' . mysql_error());
}
$result = mysql_query("SELECT * FROM Admin where AdminID = '$adminid' and Password='$pwd'")
or die(mysql_error());
if ($row = mysql_fetch_array($result))
{
}
else
{
}
}
mysql_close();
?>
[/code]

No i had checked, the nos of open blacket is equal to the nos of close bracket. Other than bracket, where you see the error could be? thanks again.
Link to comment
Share on other sites

This code (the one you last posted which now has the correct number of brackets) should work fine assuming you have the values for your various variables properly defined somewhere and assuming you put something in the currently empty if...else statement.

I tested it (cut and past and then changed variables and selects to match my setup) and it returned data no problem.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.