• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 554
  • Last Modified:

Error calling mysql stored procedure from PHP page.

Need help calling a mysql 5 stored procedure from PHP 5 web page. Windows XP home. Apache 2. MySql 5. PHP 5. The call fails but I also seem to have a syntax problem displaying the error. Calling the procedure works in MySql browser window. The procedure inserts into 2 tables and does not return a result set. Here is section of the code that calls the procedure:
$mysqli = new mysqli("locahost", "guest", "guest","mymathhelper");
if (mysqli_connect_errno())
   {      echo "<br>good connection";
      $name = ltrim(rtrim($_POST['login']));
      //$sql = "call usp_add_client($name)";
      $sql = "call usp_add_client('" . $name . "')";
      //if($result = $mysqli->query($sql))
      if($mysqli->query($sql))
         echo "<br><font color=blue>" . $_POST['login']
         . " was successfully added as your login. Click                            <a href=new_client.php> here</a>          to return to main menu.</font >" ;
      else
         echo  "<br>procedure error " . mysqli_error($mysqli);
   }
else
    echo "<br><font color=red> Connection to
    database failed. Click <a href=new_client.php> here</a>
    to return to main menu.</font >" ;                  
0
MathHelper
Asked:
MathHelper
1 Solution
 
babuno5Commented:
put this line above your script and check if any errors are there
error_reporting(1);
0
 
steelseth12Commented:
$mysqli = new mysqli("locahost", "guest", "guest","mymathhelper");
if (mysqli_connect_errno()){      

      echo "<br><font color=red> Connection to
      database failed. Click <a href=new_client.php> here</a>
      to return to main menu.</font >" ;
      
}else{
      
       echo "<br>good connection";
      
      $name = trim($_POST['login']);
      
      $sql = "call usp_add_client('" . $name . "')";
      
      
      if($mysqli->query($sql)) {
      
      echo "<br><font color=blue>" . $_POST['login']." was successfully added as your login. Click <a href=new_client.php> here</a> to return to main menu.</font >" ;
      
      }else{
            
            echo  "<br>procedure error " . mysqli_error($mysqli);
      }        
      
}
0
 
MathHelperAuthor Commented:
The solution provided revealed I was mistaking false for true in the code "if (mysqli_connect_errno())". I then changed that code to "if (mysqli_connect_errno() == 0). I was then able to display the error code that indicated that I had misspelled localhost as "locahost".
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now