Jump to content

nickRSA

New Members
  • Posts

    3
  • Joined

  • Last visited

nickRSA's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Good day guys, having some issues getting the following to work: <?php $db = new PDO('sqlite:test22.db'); function insertMember($db, $firstname, $sname ){ $sql = sprintf("INSERT INTO info (name, surname) VALUES ( "%s", '%s' '%s')"); echo $sql . '<br/>'; $db->query($sql); } $firstname = array( 'Johnathon', 'Anthony', 'Erasmo', 'Raleigh', 'Nancie', 'Tama', 'Camellia', 'Augustine', ); $lastname = array( 'Mischke', 'Serna', 'Pingree', 'Mcnaught', 'Pepper', 'Schildgen', 'Mongold', 'Wrona', 'Geddes', 'Lanz', ); $name = $firstname[rand ( 0 , count($firstname) -1)]; $name .= ' '; $surname = $lastname[rand ( 0 , count($lastname) -1)]; insertMember($db, $name, $surname); ; ?> The video tutorial I followed made use of "%s" but for some reason my browser tells me the syntax is incorrect. I am a bit lost, as I am relatively new to PHP as a whole. Any assistance would be appreciated. Cheers!
  2. 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.
  3. 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); } ?>
×
×
  • 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.