nickRSA Posted August 1, 2022 Share Posted August 1, 2022 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315118-sending-html-table-data-to-sqlite-db/ Share on other sites More sharing options...
requinix Posted August 1, 2022 Share Posted August 1, 2022 If you're using PDO and SQLite then why is there calls to mysqli_query and mysqli_close in there? Quote Link to comment https://forums.phpfreaks.com/topic/315118-sending-html-table-data-to-sqlite-db/#findComment-1598860 Share on other sites More sharing options...
nickRSA Posted August 1, 2022 Author Share Posted August 1, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315118-sending-html-table-data-to-sqlite-db/#findComment-1598863 Share on other sites More sharing options...
Barand Posted August 1, 2022 Share Posted August 1, 2022 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 ] ); Quote Link to comment https://forums.phpfreaks.com/topic/315118-sending-html-table-data-to-sqlite-db/#findComment-1598869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.