Jump to content


Photo

MySQL_Close error


  • Please log in to reply
8 replies to this topic

#1 u0206787@nus.edu.sg

u0206787@nus.edu.sg
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 29 September 2006 - 10:42 AM

$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);
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.



#2 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 29 September 2006 - 11:33 AM

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

and when using mysql_close you dont have to specify the link identifier. it can simply be:
mysql_close();
and it will close the last open connection.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 u0206787@nus.edu.sg

u0206787@nus.edu.sg
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 29 September 2006 - 11:44 AM

you should have to put

$db=mysql_select_db($database, $connect);
you can just put:
mysql_select_db($database, $connect);

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


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.

#4 u0206787@nus.edu.sg

u0206787@nus.edu.sg
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 September 2006 - 03:26 AM

<?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(); 

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.


#5 Gaoshan

Gaoshan
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 30 September 2006 - 05:11 AM

mysql_close($connect)


#6 u0206787@nus.edu.sg

u0206787@nus.edu.sg
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 September 2006 - 05:25 AM

mysql_close($connect)

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?

#7 Gaoshan

Gaoshan
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 30 September 2006 - 05:38 AM

You are missing a closing bracket. The if statement is never closed in the code you posted.

#8 u0206787@nus.edu.sg

u0206787@nus.edu.sg
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 September 2006 - 05:56 AM

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(); 
?>

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.

#9 Gaoshan

Gaoshan
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 30 September 2006 - 06:56 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users