从sql中获取信息并将其放入表单中 [英] Get information out of sql and put it in a form
本文介绍了从sql中获取信息并将其放入表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP
<?php
$ id = $ _GET ['id'];
$ conn = mysql_connect(localhost,root,)或die(mysql_error());
mysql_select_db(赋值3,$ conn);
$ sql =select schoolname FROM schooltable WHERE id = $ id;
$ result = mysql_query($ sql,$ conn)或die(mysql_error());
($ row = mysql_fetch_assoc($ result)){
foreach($ row as $ name => $ value){
print$ name = $ value< / BR>中;
}
}
mysql_data_seek($ result,0);
while($ row = mysql_fetch_assoc($ result)){
//从用户列表中选择id,firstname,lastname
$ school = $ row [schoolname];
$ grad = $ row [lastname];
}
?>
HTML
< div class =form-group>
< label class ='col-xs-4 control-label'>你去过什么学校为本科学习? < /标签>
< div class ='col-xs-8'>
< select class =form-control backgroundid ='dropdown'>
< option><?php print $ schoolname?>< / option>
< option><?php print $ schoolname?>< / option>
< option><?php print $ schoolname?>< / option>
< option><?php print $ schoolname?>< / option>
< option value =bing><?php print $ schoolname?>< / option>
< / select>
< input type =hiddenname =idid ='id'value =<?php print $ id?>>
< input type =hiddenname =editModevalue =edit>
< / div>
解决方案
<?php
if(!isset($ _ GET ['id']]){
$ echo'id = not in present in URL。Exiting。';
return false;
}
$ id = intval($ _ GET ['id']);
$ conn = mysql_connect(localhost,root,MIS42520!$)或die(mysql_error());
$ b $ mysql_select_db(assignment 3,$ conn);
$ sql =select * FROM schooltable WHERE id ='。mysql_real_escape_string($ id)。';
$ result = mysql_query($ sql,$ conn)或die(mysql_error());
$ schools = array();
while($ row = mysql_fetch_assoc($ result)){
$ [] = $ row;
$>
< div class =form-group>
< label class ='col-xs-4 control-label '>你去学校的什么学校?< / label>
< div class ='col-xs-8'>
< select class =form-control background id = 'dropdown'>
<?php foreach($ schools as $ school){?>
< option value =<?php echo $ school ['schoolname'];?>><?php echo $ school ['schoolname'];?>< / option>
<?php}?>
< / select>
< input type =hiddenname =idid ='id'value =<?php echo $ id?>>
< input type =hiddenname =editModevalue =edit>
< / div>
< / div
So I need to get information out of sql and put it in my dropdown in my form. Here's what I have... I'm very lost.. The info has been prepopulated into sql. I believe the top part is relatively right and then I don't know how to reference it in the form.
PHP
<?php
$id= $_GET['id'];
$conn = mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("assignment 3", $conn);
$sql = "select schoolname FROM schooltable WHERE id=$id";
$result=mysql_query($sql, $conn) or die(mysql_error());
while ($row=mysql_fetch_assoc($result)){
foreach($row as $name => $value){
print "$name = $value</br>";
}
}
mysql_data_seek($result, 0);
while ($row=mysql_fetch_assoc($result)){
//select id, firstname, lastname from userlist
$school = $row["schoolname"];
$grad = $row["lastname"];
}
?>
HTML
<div class="form-group">
<label class='col-xs-4 control-label'>What school did you go to for your undergrad? </label>
<div class='col-xs-8'>
<select class="form-control background" id='dropdown'>
<option>"<?php print $schoolname ?>"</option>
<option>"<?php print $schoolname ?>"</option>
<option>"<?php print $schoolname ?>"</option>
<option>"<?php print $schoolname ?>"</option>
<option value="bing">"<?php print $schoolname ?>"</option>
</select>
<input type="hidden" name="id" id='id' value="<?php print $id ?>">
<input type="hidden" name="editMode" value="edit">
</div>
</div
解决方案
Here you go
<?php
if(!isset($_GET['id']]){
echo 'id= not present in URL. Exiting.';
return false;
}
$id = intval($_GET['id']);
$conn = mysql_connect("localhost", "root", "MIS42520!$") or die (mysql_error());
mysql_select_db("assignment 3", $conn);
$sql = "select * FROM schooltable WHERE id='" . mysql_real_escape_string($id) . "'";
$result = mysql_query($sql, $conn) or die(mysql_error());
$schools = array();
while ($row = mysql_fetch_assoc($result)) {
$schools[] = $row;
}
?>
<div class="form-group">
<label class='col-xs-4 control-label'>What school did you go to for your undergrad? </label>
<div class='col-xs-8'>
<select class="form-control background" id='dropdown'>
<?php foreach($schools as $school){?>
<option value="<?php echo $school['schoolname'];?>"><?php echo $school['schoolname'];?></option>
<?php } ?>
</select>
<input type="hidden" name="id" id='id' value="<?php echo $id ?>">
<input type="hidden" name="editMode" value="edit">
</div>
</div
这篇关于从sql中获取信息并将其放入表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文