I am getting Undefined array key when updating data in table based on text in HTML input field [duplicate]

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

I am currently creating a survey where the answers are entered into a database.

I have 1 main table (for this issue, that is):

questions, with 2 columns: questionID and questionBody.

I am creating a page that will allow me to update questionBody and maintain the same value in questionID. So for example, if I have a value in questionBody as ‘Where is this?’, I want to be able to update that by entering a value into a HTML text field, then submitting an UPDATE MySQL statement to change it from ‘Where is this?’ to whatever I enter into the text field.

Is this possible?

Here is my code:

editQuestions.php:

<?php
//Include connect file in here
require_once “C:/xampp/htdocs/Unit 4/SAT Submission/config/config.php”;
?>

<html>
<head>
<title>Survey Admin Page</title>
<link rel=”stylesheet” href=”C:/xampp/htdocs/Unit 4/SAT Submission/CSS/style.css”>
</head>
<body>
<div class=”wrapper”>

<?php
$query = “SELECT * from questions”;
$data = mysqli_query($connect, $query);
$total = mysqli_num_rows($data);

if ($total!=0)
{
while ($result=mysqli_fetch_array($data, MYSQLI_ASSOC))
{
echo ”
<table border=’2′>
<th>Question ID</th>
<th>Question</th>
<tr>
<td>”.$result[‘questionID’].”</td>
<td>”.$result[‘questionBody’].”</td>
<td><a href = ‘delete.php?rn=$result[questionID]’>Delete</a></td>
<td><form action=’update.php’ method=’GET’>
<input type=’text’ id=’updateQuestion’ name=’updateQuestion’> <a href = ‘update.php?questionID=$result[questionID]&updateQuestion=$_GET[updateQuestion]’>Update</a>
</form>
</td>
</tr>
</table>
“;
}
}
else
{
echo “No questions found.”;
}
?>
<a href=”adminPanel.php”><p>Go back to Admin Panel</p></a>
</div>
</form>
</body>
</html>

update.php:

<?php

include(“C:/xampp/htdocs/Unit 4/SAT Submission/config/config.php”);

$questionID = $_GET[‘questionID’];
$updateQuestion = $_GET[‘updateQuestion’];

$query = “UPDATE questions SET questionBody = ‘$updateQuestion’ WHERE questionID = ‘$questionID'”;

$data = mysqli_query($connect, $query);

if($data)
{
echo “Successfully updated question. <br><br>”;
echo “<a href= adminPanel.php>Go back to Admin Panel.”;
}
else
{
echo “Failed to update question. <br><br>”;
echo “<a href= adminPanel.php>Go back to Admin Panel.”;
}
?>

At the moment the error I get after submitting is:

Warning: Undefined array key “updateQuestion” in C:xampphtdocsUnit 4SAT Submissionadminupdate.php on line 7
Successfully updated question.

Go back to Admin Panel.

Any ideas as to what I could do?

‫أضف إجابة

تصفح
تصفح

مجهول يجيب