xtops Posted October 28, 2009 Share Posted October 28, 2009 this is the error Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/www/IpSearch.php on line <?php $srch = $_REQUEST["srch"]; if (empty($srch)) { print <<<HERE <form> Type the Store location: <input type = "text" name = "srch"> <input type = "submit"> </form> HERE; } else { $con = mysql_connect("localhost","root","icebird"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("IpPhoneDir", $con); // Send a query to the server if ($result = mysql_query($con, "call GetBranchBeg($srch)")) { $um_rows = mysql_num_rows($result); if($num_rows <= 0) { echo "no match found"; } print "<table border = 1>\n"; //get row data as an associative array While ($row = mysql_fetch_assoc($result)) { print "<tr>\n"; //look at each field foreach ($row as $col=>$val){ print "<td>$val</td>\n"; }//end foreach print "</tr>\n\n"; }//end while- print "</table>\n"; } else { trigger_error(mysql_error(),E_USER_WARNING); //this will display MySQL's error message } } mysql_close($con) ?> DROP PROCEDURE `GetBranchBeg`// CREATE DEFINER=`root`@`localhost` PROCEDURE `GetBranchBeg`(IN starts_with CHAR(15)) BEGIN DECLARE tmp CHAR(15); SET tmp = CONCAT(starts_with, '%'); SELECT IpPhoneNo, location FROM IpPhoneList WHERE location LIKE tmp OR location =starts_with; END Quote Link to comment https://forums.phpfreaks.com/topic/179332-whats-wrong-with-my-code-plz-help/ Share on other sites More sharing options...
asmith Posted October 28, 2009 Share Posted October 28, 2009 I don't know what exactly you've done here: ($result = mysql_query($con, "call GetBranchBeg($srch)")) But Why your $con is the first argument? Try switching them first: ($result = mysql_query("call GetBranchBeg($srch)", $con)) Quote Link to comment https://forums.phpfreaks.com/topic/179332-whats-wrong-with-my-code-plz-help/#findComment-946177 Share on other sites More sharing options...
xtops Posted October 29, 2009 Author Share Posted October 29, 2009 i already try your suggestion but still with this error Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/www/IpSearch.php on line and this error when i click submit button Warning: Procedure IpPhoneDir.GetBranchBeg can't return a result set in the given context Quote Link to comment https://forums.phpfreaks.com/topic/179332-whats-wrong-with-my-code-plz-help/#findComment-946836 Share on other sites More sharing options...
keldorn Posted October 29, 2009 Share Posted October 29, 2009 You have the mysq_close out of the else statement which means it gets called even if there was no database connection (which happens in the else statement). Hence the error, since ther eis nothing to close try this. <?php $srch = $_REQUEST["srch"]; if (empty($srch)) { print <<<HERE <form> Type the Store location: <input type = "text" name = "srch"> <input type = "submit"> </form> HERE; } else { $con = mysql_connect("localhost","root","icebird"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("IpPhoneDir", $con); // Send a query to the server if ($result = mysql_query($con, "call GetBranchBeg($srch)")) { $um_rows = mysql_num_rows($result); if($num_rows <= 0) { echo "no match found"; } print "<table border = 1>\n"; //get row data as an associative array While ($row = mysql_fetch_assoc($result)) { print "<tr>\n"; //look at each field foreach ($row as $col=>$val){ print "<td>$val</td>\n"; }//end foreach print "</tr>\n\n"; }//end while- print "</table>\n"; } else { trigger_error(mysql_error(),E_USER_WARNING); //this will display MySQL's error message } mysql_close($con) } // end of Else ?> Quote Link to comment https://forums.phpfreaks.com/topic/179332-whats-wrong-with-my-code-plz-help/#findComment-946849 Share on other sites More sharing options...
xtops Posted October 29, 2009 Author Share Posted October 29, 2009 TNX FOR THE REPLY ONLY ONE ERROR EXIST when i click submit button Warning: Procedure IpPhoneDir.GetBranchBeg can't return a result set in the given context HOW FIX THIS Quote Link to comment https://forums.phpfreaks.com/topic/179332-whats-wrong-with-my-code-plz-help/#findComment-946858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.