0

I have a code below... and sometimes this code just give me information that everything is ok, and "success" msg. But new row from insert is not added to database. I thought: echo $this->mysqli->error; will give me error but it's not working?

if ($stmt = $this->mysqli->prepare("INSERT INTO tournaments ("
                    . "id_system, "
                    . "id_rank_admin, "
                    . "id_tournament_class, "
                    . "id_season, "
                    . "tournament_name,"
                    . "description,"
                    . "city,"
                    . "address,"
                    . "tournament_date,"
                    . "start_time,"
                    . "entry_fee,"
                    . "tournament_type,"
                    . "accepted_expansions,"
                    . "prices,"
                    . "additional_info,"
                    . "status,"
                    . "organizer_name,"
                    . "organizer_logo,"
                    . "organizer_link) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)  ")) 
            {
                $stmt->bind_param("sssssssssssssssssss", 
                        $this->id_system, 
                        $this->id_rank_admin, 
                        $this->it_tournament_class,
                        $this->id_season, 
                        $this->tournament_name, 
                        $this->description, 
                        $this->city, 
                        $this->address, 
                        $this->tournament_date, 
                        $this->start_time, 
                        $this->entry_fee, 
                        $this->tournament_type, 
                        $this->accepted_expansions, 
                        $this->prices, 
                        $this->additional_info, 
                        $this->status, 
                        $this->organizer_name, 
                        $this->organizer_logo, 
                        $this->organizer_link);
                $stmt->execute();
                $stmt->close();
            }
            else
            {
                echo $this->mysqli->error;
            }
Vasquez21
  • 49
  • 5

3 Answers3

1
$ok=$stmt->execute();

if($ok)
{
  echo "Query Executed Successfully";
}
else
{
 echo(mysqli_error($link));
}

The mysqli->execute what it does is returns true or false based on it you can get your error i'm not in to too much of mysqli oop way so if any syntax is wrong correct it

NaveenThally
  • 946
  • 1
  • 6
  • 18
0

I found this here: http://php.net/manual/en/mysqli.error.php

 string mysqli_error ( mysqli $link )

Returns the last error message for the most recent MySQLi function call that can succeed or fail.

Might give you a better understanding of where the error is.

jbutler483
  • 24,074
  • 9
  • 92
  • 145
0

Try this:

$link = mysqli_connect("localhost", "my_user", "my_password", "db");

else
{
    echo(mysqli_error($link));
}
Stefan
  • 17,448
  • 11
  • 60
  • 79
user3894236
  • 114
  • 2
  • 14