BusinessAlch's avatar

Confused

Hi all,

I've put my app to live and it seems to be fine, for the most part. It reads from the database, however it doesn't write to the database. I've turned the debug to true and still nothing, no errors come up when I'm trying to write for it etc, I don't really know what else to try here.

0 likes
3 replies
gych's avatar

Check the database permissions and see if the DB user that you're using for your app has permission to INSERT records in the database.

1 like
LaryAI's avatar
Level 58

It sounds like you might be facing a permissions issue with your database or possibly a configuration problem in your application. Here are a few steps you can take to diagnose and solve the issue:

  1. Check Database User Permissions: Ensure that the database user has the correct permissions to insert and update records in the database. You can do this by logging into your database management tool (like phpMyAdmin, MySQL Workbench, etc.) and checking the user privileges.

  2. Database Connection Settings: Double-check your database connection settings in your application's configuration file. For a Laravel application, this would be in the .env file. Make sure the DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD are set correctly for your live environment.

  3. Database Write Operations: Look at the code where the write operations are supposed to happen. Make sure you are using the correct methods for saving data to the database (e.g., save(), create(), update() in Laravel).

  4. Error Logging: If debug mode is on and you're not seeing any errors, check the logs. In a Laravel application, the logs can be found in the storage/logs directory. There might be some clues there.

  5. Database Migrations: Ensure that all necessary database migrations have been run on the live server. You can do this by running php artisan migrate in the terminal from your project directory (if you're using Laravel).

  6. Middleware and Request Validation: If you're using middleware or request validation, ensure that the data is passing through as expected and that there are no validation errors preventing the data from being saved.

  7. Test with Tinker (Laravel): If you're using Laravel, you can use Tinker to manually attempt to write to the database. Run php artisan tinker and then try to create a new record in the database to see if it works.

Here's an example of how you might do this in Laravel Tinker:

$user = new App\Models\User;
$user->name = 'Test User';
$user->email = '[email protected]';
$user->password = bcrypt('password');
$user->save();

If this works, then the issue might be somewhere in your application code.

  1. Check for Read-Only Filesystem: In some deployment environments, the filesystem might be set to read-only mode. Make sure that your application has the ability to write to the filesystem if necessary.

  2. Database Engine Specific Issues: If you're using a database like MySQL, check for any engine-specific issues that might prevent writes, such as a full disk or a read-only transaction.

If you've gone through all these steps and still can't find the issue, you might want to provide more specific information about your application, the database you're using, and the code that's supposed to write to the database so that others can help you troubleshoot further.

BusinessAlch's avatar
BusinessAlch
OP
Best Answer
Level 3

After too many hours facing this issue, I found out that it was the post URL I was using '/admin/customers/create/' it needed to be '/admin/customers/create'... it hurts, it actually physically hurts 😭

Please or to participate in this conversation.