-1

I am trying to insert records into MySQL database using PHP. Initially, the records were inserted into the database. After sometimes, it stopped inserting. There are no error messages displayed.

PHP code:

<?php
    require('dbconnect.php');
    if( isset($_POST['submit'] ) ){
        $fullname=$_POST['fullname'];
        $type=$_POST['type'];
        $price=$_POST['price'];
        $mmnumber=$_POST['mmnumber'];

        mysqli_query( $connect,"INSERT INTO `tickets`(fullname,type,price,mmnumber) VALUES('".$fullname."','".$type."','".$price."','".$mmnumber."')");
    }
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • I don't know what `dbconnect.php` contains but nothing in the code you've shared instructs PHP to display error messages upon error. In any case, as already noted, you're injecting raw input into your SQL and executing it so your script should be expected to fail randomly depending on user input. – Álvaro González Jul 13 '19 at 14:29

1 Answers1

0

I`t all about your dbconnect.php file and MySql connection timeouts. Look for: php.net mysqli documentation and MYSQLI_OPT_CONNECT_TIMEOUT setting.

When the connection timeout expires, the database connection goes down. So, you need to reconnect to DB or increase your timeout connection timer. Better way is reconnection. Try to check your connection and reconnect if it`s false:

<?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");

    /* check if server is alive */

    if ($mysqli->ping()) {
        printf ("Our connection is ok!\n");
    } else {
       printf ("Error: %s\n", $mysqli->error);
       $mysqli->close();
       $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
    }
?>
Vladimir
  • 441
  • 1
  • 4
  • 14