1. PHP Bug Example: Form Not Submitting
📄 Code:
❌ Bug:
Submitting the form shows nothing, even though no error appears.
🔍 Debugging Steps:
✅ Step 1: Check if $_POST['submit']
is set
But wait — your form doesn’t have:
The submit button is a <button>
, not an input with a name="submit"
. So $_POST['submit']
is not being sent.
✅ Fix:
Change the PHP condition:
Now it works! ✅
🐍 2. Python Bug Example: API Returning Wrong Data
🧪 Scenario:
You’re building a Flask API:
❌ Bug:
Calling /double
with num=5
returns:
🧠 Why?
Because request.form['num']
is a string, not a number. "5" * 2
in Python results in string repetition, not math.
✅ Fix:
Convert it to an integer first:
Now:
🛡️ 3. Cybersecurity Bug Example: SQL Injection
🔥 Vulnerable PHP Code:
❌ Bug:
A hacker enters:
-
username = ' OR 1=1 --
-
password = anything
The resulting query:
This bypasses login and grants access to any user. 🔓
✅ Fix (Use Prepared Statements):
This sanitizes inputs and blocks SQL injection.
🔚 Summary Table
Example | Bug | Fix |
---|---|---|
PHP Form | $_POST['submit'] not set |
Use $_SERVER['REQUEST_METHOD'] == 'POST' |
Python API | String math instead of integer math | Use int() to convert input |
SQL Injection | User input injected into raw query | Use prepared statements |