0

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>

1 Answers1

1

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
Amr Aly
  • 3,871
  • 2
  • 16
  • 33
  • This still is not working :( Is there another route I can take? – Jessica Napolitano Mar 17 '17 at 12:58
  • Try `sudo chgrp www-data mydb.sq3`. – Amr Aly Mar 17 '17 at 18:59
  • it is saying that www-data is an invalid group name. Sorry I am also new to the idea of a group. Do I need to add a new group before i can do this? – Jessica Napolitano Mar 20 '17 at 21:26
  • That cmd was recognized but still did not fix the problem. I am still getting the error that it is a read only database. Is it possibly the way I made the database? Would it help if I made the database in the php script? I made that database using the command line – Jessica Napolitano Mar 21 '17 at 05:58
  • @JessicaNapolitano one last thing before that `sudo chgrp -R _www your_folder` and don't give up if i couldn't solve your problem there is always a way to solve a problem. – Amr Aly Mar 21 '17 at 06:10
  • Unfortunately I am still getting the error even after running that line in the the terminal with my folder path inputed instead of your_folder – Jessica Napolitano Mar 21 '17 at 14:36
  • 1
    Have u tried to check the permissions for the folder containing the database check this [video](https://www.youtube.com/watch?v=7mx2XOFBp8M) – Amr Aly Mar 21 '17 at 17:29
  • OH MY GOSH IT WORKED!!!!!! Thank you so so so much. Wow I had really given up. Thank you so much for your patience and persistence. You are amazing. Thank you! I am not sure if you want to make what you just said an answer and then I can upvote it. – Jessica Napolitano Mar 21 '17 at 18:02
  • 1
    No need since it's not my video. I just searched for it. – Amr Aly Mar 21 '17 at 19:08