dimanche 3 novembre 2019

Insert array of numbers into a single collumn , MySQL, PHP

So what I am trying that I am creating an array of 500 random numbers, and trying to send them into the database.

But Every time I run the program there is only 1 value get inserted in the database and that value is 0.

The query runs successfully but the data won't get inserted.

Here is what I have tried.

Create a random data of 500 numbers:

$data = [] ;

for($i=0; $i<500; $i++)
 {
  $data[] = rand(0,10);  
 }

$into_mysql = json_encode($data);

Query to send the data in the MySQL table:

  $query = "INSERT INTO points(value) VALUES ('$into_mysql')";

  mysqli_query($conn, $query);

  echo "\n Data Inserted Successfully";

In the output, I am getting Data Inserted Successfully. but the database column only gets 0 entry as you can see : enter image description here

Please correct me If I am doing something wrong.




Aucun commentaire:

Enregistrer un commentaire