所以我有一个用于编辑数据库中现有文章的表单。它看起来像这样:
<div id="a_EditDiv">
<h2 id="H-a_Edit">Edit an existing article</h2>
<form id="F-a_New" action="editarticle.php" method="post" onsubmit="a_Editvalidate();">
<fieldset>
<legend>Edit an existing article: </legend>
<select>
<option value="1">1</option>
<option value="2">2</option>
</select>
<label for="a_Title_Edit">Article title: </label>
<br/>
<input type="text" name="a_Title_Edit" id="a_Title_Edit" value="" />
<span id="err_a_Title_Edit"></span>
<br/>
<label for="a_Details_Edit">Article Details </label>
<br/>
<textarea rows="30" cols="" name="a_Details_Edit" id="a_Details_Edit"></textarea>
<br/>
<div id="a_Details-rmn_Edit">Remaining characters: 8192/8192</div>
<span id="err_a_Details_Edit"></span>
<div>
<pre>
<code>
You may use the following html tags:
<a href=""></a>
<b></b> <i></i> <u></u>
<object></object>
Please use:
&lt; = < &gt; = >
&euro = € &dollar; = $ &pound; = £
&amp; = &
&copy; = © &reg; = ®
Please DO NOT use any other HTML tags.
</code>
</pre>
</div>
<label for="a_Author_Edit">Author: </label>
<br/>
<input type="text" value="admin" name="a_Author_Edit" id="a_Author_Edit" readonly="readonly" />
<span id="err_a_Author_Edit"> </span>
<br/>
<input class="gray_button" type="button" value="Edit Author" />
<br/>
<label for="a_Timestamp">Timestamp: </label>
<br/>
<input type="text" value="<?php echo date('d-m-Y') . ' ' . strtoupper(date('h:i:sa'));?>" name="a_Timestamp_Edit" id="a_Timestamp_Edit" readonly="readonly" />
<br/>
<input class="gray_button" type="button" value="Edit Timestamp" id="a_Timestamp-enable" />
<br/><br/>
<input class="gray_button" type="submit" value="Edit Article" />
<br/>
<span id="err_a_Edit"></span>
<?php
if(isset($_GET["article"])){
if($_GET["article"] === "success"){
echo "Article successfully published.";
} else if($_GET["article"] === "failed"){
echo "Article was not published.";
}
}
?>
</fieldset>
</form>
</div>
是的......大代码。因此,当我更改<select>
元素的值时,我希望输入字段根据<select>
元素的值填充文章的标题,详细信息等。
所以我需要查询数据库以检索与<select>
的值相对应的值,然后将<input>
元素的值设置为相应的值。我可以轻松地UPDATE articles WHERE ID = value of select id
,但我不想这样做,我想要一种互动的方式来做到这一点,通过这样做,编辑可以看到帖子已经是什么样的。
答案 0 :(得分:0)
经过长时间的研究后,我找到了答案。在W3Schools上有一个PHP,AJAX和MySQL教程,它给了我完美的解决方案。它很容易找不到。