Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading values into text area from database and then edit/update database with new values in PHP?
    primarykey
    data
    text
    <p>I am trying to make a CMS for FAQs.</p> <p>I have a page that loads the questions and answers into text-areas with unique ideas and the plan is too edit these text areas and then insert them in the database.</p> <p>I would like to be able to add new FAQS to the database as well.</p> <p>Right now I am trying to accomplish this with a <code>ON DUPLICATE KEY UPDATE..</code> but it does not work properly.</p> <p>index.php</p> <pre><code> &lt;form id='faqadd' action='faqsql.php' method='POST'&gt; &lt;?PHP include 'include.php'; $query = 'SELECT * FROM FAQ'; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $val = 1; while($row=mysql_fetch_array($result)){ echo '&lt;div class="faq['.$val.']"&gt;&lt;label&gt; Question &lt;/label&gt;&lt;input type="hidden" name="id['.$val.']"&gt;&lt;/input&gt;&lt;textarea rows="8" cols="50" id="q['.$val.']" &gt;'.$row["question"].'&lt;/textarea&gt;&lt;br /&gt; &lt;label&gt; Answer &lt;/label&gt;&lt;textarea rows="4" cols="50" name="a['.$val.']" &gt;'.$row["answer"].'&lt;/textarea&gt;&lt;/div&gt;&lt;br /&gt;'; $val++; } echo '&lt;h3 style="color:white;"&gt;New FAQ &lt;/h3&gt;'; echo '&lt;div class="faq['.$val.']"&gt;&lt;label&gt; Question &lt;/label&gt;&lt;textarea rows="8" cols="50" id="q['.$val.']" &gt;&lt;/textarea&gt;&lt;br /&gt; &lt;label&gt; Answer &lt;/label&gt;&lt;textarea rows="4" cols="50" name="a['.$val.']" &gt;&lt;/textarea&gt;&lt;/div&gt;&lt;br /&gt;'; ?&gt; &lt;input type='submit' name='ADD' value='ADD' id='ADD'&gt; &lt;/form&gt; </code></pre> <p>faqsql.php</p> <pre><code>foreach ($_POST['id'] as $id) { if ($id) { $query = 'INSERT INTO FAQ ("id", "question", "answer") VALUES ("' . $id . '","' . $_POST["q"] . '", "' . $_POST["a"] . '") ON DUPLICATE KEY UPDATE "question" = "' . $_POST["q"] . '", "' . $_POST["a"] . '"'; $result = mysql_query($query) or die("Error in query: $query. " . mysql_error()); echo $id . " has been added &lt;/br &gt; "; } } echo '&lt;a href="editfaq.php"&gt;Back FAQ Manager &lt;/a&gt;'; </code></pre> <p>What should I try next?</p> <p>Updated Code. Still not working.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload