Jessica Napolitano
Jessica Napolitano

Reputation: 43

XAMPP sqlite data base with PHP

Someone recently marked my question as a duplicate however I don't think it is but I am not sure how to unmark it and now I don't think anyone will answer it so I am just reposting it and saying that it is not a duplicate.

I am trying to make a website that has a database connected to it. I am on a Mac. I downloaded XAMPP and have developed the form on my webpage that I am going to use to get data from the user. I have tested that and it seems to be working. I then followed XAMPP instructions on how to create a sqlite db through the terminal and then connect to that database through php. I was able to read things from that database with a select statement however when I went to go insert into it, it said that it was a read only copy and that I could not insert. I was wondering if there was a line of code that I was missing? Or some setting that I had to change?

I looked into making a folder writable but there are conflicting things out there and I don't want to mess anything up if that really is the problem.

Here is a picture of the error that is displaying

Here is a picture of the error that is displaying

Here is my PHP code, I can also share the HTML if you need it:

    <html> 

    <style type="text/css">
    body {background-color:#666666; color: white;}
    </style> 

    <body>
    <h1 align = "center">

    <img src="housebackground.jpg" alt="Mountain View" style="width:97%;height:228px;" ></h1>

    <h1 align = "center">Submission Status</h1>

    <?php
       $db = new SQLite3('mydb.sq3');

       $StructureName = $_POST["StructureName"];
       $Author = $_POST["Author"];
       $YearBuilt = $_POST["YearBuilt"];
       $EraBuilt = $_POST["EraBuilt"];
       $YearDestroyed = $_POST["YearDestroyed"];
       $EraDestroyed = $_POST["EraDestroyed"];
       $Latitude = $_POST["Latitude"];
       $Longitude = $_POST["Longitude"];
       $StructureLink = $_POST["StructureLink"];


       $db->exec("INSERT INTO info VALUES (null, '$StructureName', '$Author', $YearBuilt, '$EraBuilt', $YearDestroyed, '$EraDestroyed', $Latitude, $Longitude, '$StructureLink');"); 


       unset($db); 
    ?>

    <br><br>
    </body>
    </html>

Upvotes: 0

Views: 771

Answers (1)

Amr Aly
Amr Aly

Reputation: 3905

First of all change the permissions for the file

sudo chmod 775 mydb.sq3

Second change the directory permissions

sudo chmod -R 775 the_path_to_your_folder

Upvotes: 1

Related Questions