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 >" ;                  
MathHelperAsked:
Who is Participating?
 
steelseth12Connect With a Mentor Commented:
$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
 
babuno5Commented:
put this line above your script and check if any errors are there
error_reporting(1);
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.