# 🚀 Brisco PHP Backend - Upload & Deploy

## 📦 **What You Get**

A complete PHP backend that you can upload to ANY web server with PHP and MySQL. **No dependencies, no Node.js, no complications!**

## 📁 **Files to Upload**

Upload this entire folder to your web server:

```
brisco-php-backend/
├── api.php              # Main API endpoints
├── admin.html           # Beautiful admin dashboard
├── database.sql         # Database setup file
├── config.php           # Database configuration
├── .htaccess            # URL rewriting & security
└── README.md            # This guide
```

## 🗄️ **Database Setup (2 Ways)**

### Option 1: Easy phpMyAdmin
1. Login to your hosting control panel
2. Open phpMyAdmin
3. Create database: `brisco_db`
4. Click on `brisco_db`
5. Click "Import" tab
6. Choose `database.sql` file
7. Click "Go" ✅

### Option 2: Direct SQL
Run this SQL in your database:
```sql
-- Copy contents from database.sql file
```

## ⚙️ **Configuration (1 Step)**

Edit `config.php` with your database details:

```php
<?php
define('DB_HOST', 'localhost');        // Usually localhost
define('DB_NAME', 'brisco_db');        // Database name
define('DB_USER', 'your_db_username'); // Your database username
define('DB_PASS', 'your_db_password'); // Your database password
?>
```

## 🌐 **Your URLs**

After uploading, your URLs will be:

- **API**: `https://yourdomain.com/brisco-php-backend/api.php`
- **Admin**: `https://yourdomain.com/brisco-php-backend/admin.html`
- **Health Check**: `https://yourdomain.com/brisco-php-backend/api.php/api/health`

## 📱 **API Endpoints**

### Products
- `GET /api.php/api/products` - Get all products
- `GET /api.php/api/products/{id}` - Get single product
- `POST /api.php/api/products` - Create product
- `PUT /api.php/api/products/{id}` - Update product
- `DELETE /api.php/api/products/{id}` - Delete product

### Categories
- `GET /api.php/api/categories` - Get all categories

### Authentication
- `POST /api.php/api/auth` - Login

## 🔧 **Example API Usage**

### Get all products
```javascript
fetch('https://yourdomain.com/brisco-php-backend/api.php/api/products')
  .then(response => response.json())
  .then(data => console.log(data.products));
```

### Create product
```javascript
fetch('https://yourdomain.com/brisco-php-backend/api.php/api/products', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    id: 'beef_steak_premium',
    name: 'Premium Beef Steak',
    description: 'High-quality beef steak',
    price: 299.99,
    category: 'beef',
    unit: 'kg',
    imageUrl: 'https://example.com/steak.jpg'
  })
});
```

## 📱 **Android App Integration**

Update your Android app to use the new API:

```java
// In your CategoryActivity.java
private static final String API_BASE = "https://yourdomain.com/brisco-php-backend/api.php/api/";

// Example method
private void loadProductsFromAPI() {
    String url = API_BASE + "products?category=" + categoryId;
    
    // Use your HTTP client (Volley, Retrofit, etc.)
    // Parse JSON response
}
```

## 🔐 **Security (Recommended)**

### Basic Admin Protection
Create `.htaccess` in the same directory:
```apache
AuthType Basic
AuthName "Brisco Admin Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
```

### Generate .htpasswd
Use an online generator to create:
- Username: `admin`
- Password: `your-secure-password`

## 🚀 **Quick Start Checklist**

### ✅ Before Upload
- [ ] Have hosting login details
- [ ] Know database credentials
- [ ] Have FTP/SFTP access

### ✅ Upload Process
- [ ] Upload all files to web server
- [ ] Create database `brisco_db`
- [ ] Import `database.sql`
- [ ] Edit `config.php` with database details
- [ ] Test API: Visit your API URL
- [ ] Test admin: Visit admin.html

### ✅ Test Everything
- [ ] API returns products: `GET /api.php/api/products`
- [ ] Admin dashboard loads
- [ ] Can add products via admin
- [ ] Android app can connect

## 🔍 **Troubleshooting**

### Common Issues & Solutions

#### "Database connection failed"
- **Fix**: Check database credentials in `config.php`
- **Fix**: Verify database exists and user has permissions

#### "404 Not Found"
- **Fix**: Files uploaded to correct directory
- **Fix**: URL is correct
- **Fix**: `.htaccess` is working

#### "500 Internal Server Error"
- **Fix**: Check PHP error logs
- **Fix**: File permissions (755 for folders, 644 for files)
- **Fix**: PHP version (requires 7.0+)

#### "CORS Error" in Android
- **Fix**: CORS headers are set in `api.php`
- **Fix**: Your domain is allowed

### Debug Mode
Edit `config.php`:
```php
define('DEBUG_MODE', true);
```

## 📊 **Features Included**

### ✅ Product Management
- Full CRUD operations
- Search and filtering
- Pagination
- Image support
- Stock tracking
- Special pricing

### ✅ Admin Dashboard
- Beautiful modern interface
- Add/edit/delete products
- Search and filter
- Dashboard statistics
- Mobile responsive

### ✅ Database Schema
- Products table with all fields
- Categories table
- Users table for authentication
- Sample data included

### ✅ Security Features
- SQL injection protection
- Input validation
- CORS headers
- Error handling
- Password hashing

## 🎯 **Next Steps**

1. **Upload Files** → Get everything on your server
2. **Setup Database** → Import the SQL file
3. **Configure** → Edit database credentials
4. **Test** → Verify API and admin work
5. **Secure** → Add password protection
6. **Integrate** → Update Android app
7. **Deploy** → Build new APK with API

## 📞 **Server Requirements**

### Minimum Requirements
- PHP 7.0 or higher
- MySQL 5.6 or higher
- 50MB disk space
- FTP/SFTP access

### Recommended
- PHP 7.4 or higher
- MySQL 8.0 or higher
- SSL certificate (HTTPS)
- mod_rewrite enabled

## 🎉 **You're Ready!**

**That's it!** You now have a complete backend system that:

- ✅ Works on ANY PHP/MySQL hosting
- ✅ Requires NO dependencies
- ✅ Has beautiful admin interface
- ✅ Supports all your product needs
- ✅ Integrates with Android app
- ✅ Is secure and production-ready

**Just upload, configure, and go!** 🚀✨

---

**Need help?** Check the troubleshooting section or test your API endpoints directly in your browser!
