How do I populate several text input fields with corresponding data, executing php-mysql query script once only? e.g.
<form name="video" action="mysql.php" method="post" enctype="multipart/form-data" target="videofrm">
<p>
<label for="url">url/gallery:</label><input class="text" type="text" id="url" name="url"/>
<input id="favorite" class="text" type="checkbox" name="favorite" value="true"/>
<label for="favorite" class="noneFloat">favorite</label>
</p>
<p>
<input id="thumb" type="file" name="thumb"/>
开发者_JAVA百科 </p>
<p>
<label for="title">title:</label><input class="text" type="text" id="title" name="title"/>
</p>
<p>
<label for="desc">description:</label><input class="text" type="text" id="desc" name="description"/>
</p>
<p>
<label for="country">country:</label><input class="text" type="text" id="country" name="country"/>
</p>
<p>
<label for="categories">categories:</label><input class="text" type="text" id="categories" name="category"/>
</p>
<input type="button" value="fetch" id="fetch"/>
<input type="reset" value="clear"/>
</form>
I need to populate input text fields with:
select url,title,desc,country,category
from video where url='something';
First I need to know how to write this kind of php script so it returns json datatype, and afterwards how to populate text input fields, using jquery, with returned data.
`many thanks
Your question is very broad, and looks a bit like a "please write my code" request (although it wasn't necessarily one). Try to avoid that impression, and mention what you have already tried/researched to avoid downvoting.
Some pointers:
Use
json_encode()
to get mySQL result data into JSON form on PHP sideSend the correct content-type header to go with it:
header("content-type: application/json");
Use jQuery's
getJSON()
shorthand (or.ajax()
with ajson
dataType) to fetch the scriptPopulating the input fields with the data is trivial using
.val()
.
精彩评论