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>
13
  • I think you have missing single quotations in two of your variables $Latitude and $Longitude Commented Mar 15, 2017 at 23:08
  • @AmrAly Hm I don't think I need them there or around the YearBuilt and YearDestroyed since they are integers and floats. Commented Mar 15, 2017 at 23:28
  • Actually i think you need them. have you tried what i've suggested? Commented Mar 15, 2017 at 23:30
  • 1
    Your query is open for SQL injection.. be careful Commented Mar 16, 2017 at 1:25
  • 1
    Possible duplicate of SQLite: read-only database Commented Mar 16, 2017 at 4:03

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

9 Comments

This still is not working :( Is there another route I can take?
Try sudo chgrp www-data mydb.sq3.
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?
Have u tried to check the permissions for the folder containing the database check this video
No need since it's not my video. I just searched for it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.