繁体   English   中英

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

[英]Get information out of sql and put it in a form

因此,我需要从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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM