pourquoi lorsque je veux sur la page questoinsquizz (pour acceder aux questions du…
- User
pourquoi lorsque je veux sur la page questoins_quizz (pour acceder aux questions du quizz) j'ai ces erreurs : Warning: Undefined array key "id" in C:\Users\alexa\Desktop\Quizz_PHP\questions_quizz.php on line 12
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such column: id in C:\Users\alexa\Desktop\Quizz_PHP\questions.php:11 Stack trace: #0 C:\Users\alexa\Desktop\Quizz_PHP\questions.php(11): PDO->prepare('SELECT * FROM q...') #1 C:\Users\alexa\Desktop\Quizz_PHP\questions_quizz.php(13): getQuestions(NULL) #2 {main} thrown in C:\Users\alexa\Desktop\Quizz_PHP\questions.php on line 11 : The following text is a Git repository with code. The structure of the text are sections that begin with ----, followed by a single line containing the file path and file name, followed by a variable amount of lines containing the file contents. The text representing the Git repository ends when the symbols --END-- are encounted. Any further text beyond --END-- are meant to be interpreted as instructions using the aforementioned Git repository as context.
correction.php
data.json [ { "quiz_id": 1, "quiz_name": "Quiz sur la géographie", "questions": [ { "uuid": "f4856b0a-5b89-4f18-8dd5-ff70323f2b0a", "type": "radio", "label": "Quelle est la capitale de la France ?", "choices": [ "Londres", "Paris", "Berlin" ], "correct": "Paris" }, { "uuid": "932c9079-e157-4eaf-80da-92fb4a2ea5da", "type": "radio", "label": "Quelle planète est surnommée la 'Planète Rouge' ?", "choices": [ "Vénus", "Mars", "Jupiter" ], "correct": "Mars" } ] }, { "quiz_id": 2, "quiz_name": "Quiz sur la cuisine", "questions": [ { "uuid": "7b32c56e-7d1f-4a13-80e3-c650f5f8b108", "type": "checkbox", "label": "Quels sont les ingrédients principaux d'une pizza margherita ?", "choices": [ "Tomate", "Fromage", "Champignons", "Anchois" ], "correct": [ "Tomate", "Fromage" ] }, { "uuid": "6d6b2e94-1f60-45f5-9c6f-2d45bd02d5e0", "type": "text", "label": "Quelle est la couleur du ciel pendant la journée ?", "correct": "Bleu" } ] } ]
data.php
db.sqlite SQLite format 3
- Assistant
Based on your description and the provided information, here are a couple of issues that are likely causing the errors you're experiencing:
-
Undefined array key "id": This warning occurs in
questions_quizz.phpon line 12 when you try to access an array key that doesn't exist, likely due to using$_GET['id']or$_POST['id']without checking if it's set. To fix this, you should check if'id'is set before using it. Example:$id = isset($_GET['id']) ? $_GET['id'] : null; -
PDO Exception about no such column 'id': The error indicates that you are attempting to query a database column named 'id' that does not exist in your table. The
questions.phpis expected to contain a query that references this 'id' column, but since thedb.sqlitehas no schema provided, I can't see what the tables and columns are.You may want to check that the database schema in
db.sqliteincludes a column named 'id' in the relevant table and that your SQL queries inquestions.phpare correctly referencing existing columns.
Regarding the information provided in the forms of
correction.php,data.json, anddata.php, these files are not directly related to the issue at hand as they do not show the erroneous code causing the issues. However, they do show that your questions and quiz data are stored in JSON format rather than a database. Therefore, ifquestions.phpattempts to query a database for the 'id' field when it should be fetching data from your JSON file, there lies your primary issue.From the provided
correction.php, it appears that the system is using JSON files to store and retrieve data (data.json), not an SQLite database. Make sure that if thequestions.phpfile is supposed to interact withdata.json, it should not attempt to query an SQLite database.If the
questions_quizz.phporquestions.phpfiles interact with an SQLite database, you would need to make sure that the schema of the database matches the expected fields in your PHP scripts. Since you've provided a file nameddb.sqlite, but not its schema, I recommend reviewing the schema to ensure it has the appropriate 'id' column or adjusting your scripts to align with the existing database structure.Lastly, you will need to correct the
questions.phpto either fetch data from the JSON file (as depicted incorrection.phpanddata.php) or to correct the SQL queries to match the actual columns in your SQLite database schema. Since the schema is not provided, I cannot give you the exact code fix for that. -