Jump to content

Sending HTML Table data to sqlite db?


nickRSA

Recommended Posts

Good day

Im having some issues trying to send my html table data to my sqlite DB.

My table data is randomly generated. It pulls names and surnames from a JS array to create an individual.  (not sure if this is relevant but just thought I might add it). Could anyone assist?

<?php

if(isset($_POST['output']))
{
    $firstname = $_POST["random-fname"];
    $surname = $_POST["random-sname"];

    $name_no = array_combine($firstname, $surname);

    $db = new PDO('sqlite:test22.db');
    if(!$db)
        echo "not connected";

foreach ($name_no as $randomUser => $user) {
    echo "$randomUser -> user";
    $res = mysqli_query($db, "INSERT into info(name,surname) values('$firstname','$surname')");
    if(!res)
    echo "Record not inserted";
        else 
            echo "INSERTED";
}

mysqli_close($db);

}

?>

 

Link to comment
Share on other sites

1 hour ago, requinix said:

If you're using PDO and SQLite then why is there calls to mysqli_query and mysqli_close in there?

I have tried many things to make it work, this was just the most recent attempt as I've been told that you can query both DBs with SQL. Having worked with mysql before, I was hoping the code would apply here too.

Link to comment
Share on other sites

To use mysqli_query () you would need to have a mysqli connection, but that will only work with mysql databases (clue is in the name) and not with SQLite.

You need to use the equivalent PDO  method.

$stmt = $db->prepare("INSERT into info(name,surname) values(?, ?)");
$stmt->execute( [ $firstname, $lastname ] );

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.