php mysql database import single cell into mysql database [closed] - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, May 14, 2023

php mysql database import single cell into mysql database [closed]

I have a .csv drop file link on a page that uploads the file into my Database and would like to know if it is possible to code the PHP file to import individual cells into a table in the column rather than the .csv columns.

The proforma(s - lots of them) that need importing, the cells are laid out separately in the .csv file, and in truth...I can't be bothered regrouping the data.

And would like to as an example, import:

Cell (B,5) into column 'X' in the table, Cell (G,1) into column 'X' in the table (etc.)

The current code for the drop file link is:

if(isset($_POST["submit_file"])){
    include 'connect.php';
    $file = $_FILES["file"]["tmp_name"];
    $file_open = fopen($file,"r");
    $k = 1;
    while(($csv = fgetcsv($file_open, 1000, ",")) !== false){
      if($k != 1){
        $username = $csv[0];
        $password = $csv[1];
        $email = $csv[2];
        $name1 = $csv[3];
        $name2 = $csv[4];
        $name3 = $csv[5]; 
        $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
        if(empty(!$username) && !empty($password)){
          $sql = "select * from ALoginTable where username = '$username' and email = '$email'";
          $result = $conn->query($sql);   
          if ($result->num_rows > 0) {
            echo "Dublicate entry for ".$username." ".$email." <br/>";
          } else {
            $sql1 = "insert into grp_orders (username,password,email,name1,name2,name3) 
     values ('$username','$param_password','$email','$name1','$name2','$name3')";
            $result1 = $conn->query($sql1);  
            if($result1){
              echo "Product successfully Added";
            }
          }
        }
      }
      $k++;
    }
}

Time and effort appreciated!

Steven



source https://stackoverflow.com/questions/76237552/php-mysql-database-import-single-cell-into-mysql-database

No comments:

Post a Comment