0

I am using below code to insert data in mysql table. But unfortunately data is not inserting. Can anyone help to solve the issue.

<?php
  $conn = mysql_connect('localhost','root','password');
  mysql_select_db('db_name',$conn);
  mysql_query("insert into users_logger_info(user_id,logged_time) values 
  ('test',NOW())");
?>
ankita patel
  • 4,201
  • 1
  • 13
  • 28
bKashOST
  • 149
  • 4
  • 11
  • 1
    Stop using deprecated mysql api use mysqli or PDO – Jens Nov 09 '17 at 09:32
  • whats the error? – romal tandel Nov 09 '17 at 09:34
  • Learn about prepared Statements to prevent sql injection – Jens Nov 09 '17 at 09:34
  • Nothing is showing. – bKashOST Nov 09 '17 at 09:34
  • 1
    _Nothing is showing..._ There is no code which is supposed to _show_ the data – B001ᛦ Nov 09 '17 at 09:35
  • Use mysql_error to get the error message – Jens Nov 09 '17 at 09:35
  • Just append `die(mysql_error())` after insert query to see the error. – Yash Parekh Nov 09 '17 at 09:47
  • **The `mysql` PHP extension is dead** -- Stop using the [`mysql` PHP extension](http://php.net/manual/en/function.mysql-connect.php). It is old, deprecated since PHP 5.5 and completely removed in PHP 7.0. Use [`mysqli`](http://php.net/manual/en/book.mysqli.php) or [`PDO_mysql`](http://php.net/manual/en/ref.pdo-mysql.php) instead. Read the answers to [this question](https://stackoverflow.com/q/12859942/4265352) to learn more about why and how. – axiac Nov 09 '17 at 09:59

3 Answers3

0

It's normal that the user_id is a string type ?

You must activate Mysql errors

As it was said, the Mysql extension is abandoned, you must use PDO or Mysqli

Y.op
  • 79
  • 1
  • 1
  • 9
0

Try this.!!

I Agree with @Y.op Because if you structured your Table's user_id as int then you are passing string to integer. It can't be possible.

If that is not the Case try below Code.

    $db = mysqli_connect('localhost','root','root','db_name'); 

    echo $eee = "INSERT INTO anime_completed (user_id,logged_time) VALUES
    ('test',NOW())";

    $exUPJDL = mysqli_query($db, $eee);
Raghav
  • 388
  • 1
  • 12
0

It's difficult to identify the solution by blank screen without any error message displayed. Try the below snippet may help you to display any error msg else would connect as expected.

$connection = mysqli_connect("localhost", "root", "password", "dbname");

     if (! $connection ) {
         die("Connection failed: " . $mysql_error());
     } 

     $sql = "INSERT INTO users_logger_info(user_id,logged_time)VALUES (1,NOW())";

      if (mysqli_query($connection, $sql)) {
          echo "New record created successfully";
      } else {
             echo "Error: " . $sql . "" . mysql_error();
      }
      mysql_close($connection);
user7325973
  • 182
  • 3
  • 17