Jump to content

whats wrong with my code plz help!!!


xtops

Recommended Posts

 

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


Link to comment
https://forums.phpfreaks.com/topic/179332-whats-wrong-with-my-code-plz-help/
Share on other sites

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

 

 

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



?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.