gpt4 book ai didi

php - 从sql中获取信息并将其放入表单中

转载 作者:行者123 更新时间:2023-11-29 12:34:54 25 4
gpt4 key购买 nike

所以我需要从 sql 中获取信息并将其放入表单的下拉列表中。这就是我所拥有的...我非常迷失..该信息已预先填充到sql中。我相信上面的部分是相对正确的,然后我不知道如何在表格中引用它。

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

最佳答案

给你

<?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

关于php - 从sql中获取信息并将其放入表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26937084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com