0

我有这个代码在文件添加医生(add_doctor.php)中运行良好:

    <form enctype="multipart/form-data" form action="add_doctor.php" method="post">
    <fieldset>

<p><font color="green"><b>Studii și Specializări:</b></font></p>
<p><b>Universitatea:</b> 
    <select name="universit"><option>Selectează</option>
    <?php // Retrieve all the university and add to the pull-down menu.
    $q = "SELECT adm_id, CONCAT_WS(' ', universitate) FROM adm ORDER BY universitate ASC";      
    $r = mysqli_query ($dbc, $q);
    if (mysqli_num_rows($r) > 0) {
        while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
            echo "<option value=\"$row[0]\"";
            // Check for stickyness:
            if (isset($_POST['universit']) && ($_POST['universit'] == $row[0]) ) echo ' selected="selected"';
            echo ">$row[1]</option>\n";
        }
    } else {
        echo '<option>Vă rugăm adăugați o Universitate prima dată.</option>';
    }
    mysqli_close($dbc); // Close the database connection.
    ?>
    </select>&nbsp;&nbsp;&nbsp;<a href="adm_universitate.php" target=_"blank">Adaugă</a><font color="red">&nbsp;*</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

但是在文件中编辑医生(edit_doctor.php)我如何插入代码以从下拉列表中的mysql表中选择大学?在下面的代码中,我可以查看来自 universitate 字段的数据,但无法更改它。如何添加下拉列表,例如上面的示例以选择其他值?

// Retrieve the doctor's information:
$q = "SELECT universitate, numele, initiala_tatalui, prenumele, numele_anterior, sex, cnp, adresa_email, specialitate, specialitate2, an_abs_univ, seria_dipl_univ, nr_dipl_univ, first_name, user_id, data_adaugarii, first_name_mod, user_id_mod, stare, cod_parafa, data_modificarii FROM adm, medici, adm1 WHERE adm.adm_id=medici.adm_id AND adm1.adm1_id=medici.adm1_id AND medic_id=$id";        
$r = @mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

// Get the doctor's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);

// Create the form:

echo '<form action="edit_doctor.php" method="post">
<fieldset>
<p><font color="green"><b>Studii și Specializări:</b></font></p>

<p>Universitatea: <input type="text" readonly name="universit" size="50" maxlength="50" value="' . $row[0] . '" />&nbsp;&nbsp;&nbsp;
...
</fieldset>
<p></p>
<p><div align="center"><input type="submit" name="submit" value="Modifică" /></p>
<input type="hidden" name="id" value="' . $id . '" />
</form>';

我尝试过这种情况:但我得到错误并且不起作用。

// Retrieve the doctor's information:
$q = "SELECT universitate, numele, initiala_tatalui, prenumele, numele_anterior, sex, cnp, adresa_email, specialitate, specialitate2, an_abs_univ, seria_dipl_univ, nr_dipl_univ, first_name, user_id, data_adaugarii, first_name_mod, user_id_mod, stare, cod_parafa, data_modificarii FROM adm, medici, adm1 WHERE adm.adm_id=medici.adm_id AND adm1.adm1_id=medici.adm1_id AND medic_id=$id";        
$r = @mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

// Get the doctor's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);

// Create the form:

echo '<form action="edit_doctor.php" method="post">
<fieldset>
<p><font color="green"><b>Studii și Specializări:</b></font></p>

<p><b>Universitatea:</b> 
<select name="universit"><option>Selectează</option>
<?php // Retrieve all the artists and add to the pull-down menu.
$q = "SELECT adm_id, CONCAT_WS(' ', universitate) FROM adm ORDER BY universitate ASC";      
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) > 0) {
    while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
        echo "<option value=\"$row[0]\"";
        // Check for stickyness:
        if (isset($_POST['universit']) && ($_POST['universit'] == $row[0]) ) echo ' selected="selected"';
        echo ">$row[1]</option>\n";
    }
} else {
    echo '<option>Vă rugăm adăugați o Universitate prima dată.</option>';
}
mysqli_close($dbc); // Close the database connection.
?>
...
</fieldset>
<p></p>
<p><div align="center"><input type="submit" name="submit" value="Modifică" /></p>
<input type="hidden" name="id" value="' . $id . '" />
</form>';

在edit_doctor.php中我需要的是从数据库中检索所有关于医生的信息,包括大学领域(基于ID医生),我希望它以与下拉列表中的add_doctor.php相同的方式进行更改(从数据库中获取) . 在 add_doctor.php 中很简单,因为我不需要收集任何数据,只需插入一个新医生。

感谢帮助。

好的,从三周开始,我非常努力地检索医生信息,并根据需要在我的数据库中进行修改。在你的帮助下,我没有成功。也许这是简单的错误语法,所以我决定将来自edit_doctor.php的整个代码放在罗马尼亚语中,称为edit_medic.php。此代码有效,但我无法从 Specialitate 和 Universitate(英语专业和大学)下拉菜单中更改值。我得到空白页,我不知道为什么。如果我想更改数据库中的当前值,请帮助添加下拉列表以选择新的大学/专业。这是我的代码:

<?php //edit_doctor.php en edit_medic.php ro
// This page is for editing a doctor record.
// This page is accessed through list_doctor.php.
//header('Content-type: text/html; charset=utf-8');
//header('Content-Type: text/html; charset=widows-cp1250' );
$page_title = 'Editează Medic';
include ('includes/header.html');

echo '<h1>Detalii Medic';
if (isset($_SESSION['first_name'])) {
echo ", {$_SESSION['first_name']}";
}
if (isset($_SESSION['user_id'])) {
echo ", User ID: {$_SESSION['user_id']}";

}
echo '!</h1>';

//aici e 1 cu cel de jos, adika daca nu e logat nu are acces la baza de date
// Display links based upon the login status:
if (isset($_SESSION['user_id'])) {

// Check for a valid user ID, through GET or POST:
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From list_doctor.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<p class="error">This page has been accessed in error1.</p>';
include ('includes/footer.html'); 
exit();
}

require ('mysqli_fa_conexiunea.php');

// Check if the form has been submitted:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$errors = array();

// Check for a first name:
if (empty($_POST['numele'])) {
    $errors[] = 'Câmpul Numele este gol !';
} else {
    $num = mysqli_real_escape_string($dbc, trim($_POST['numele']));
}

    // Check for a first name:
if (empty($_POST['initiala_tatalui'])) {
    $errors[] = 'Câmpul Inițiala Tatălui este gol !';
} else {
    $ita = mysqli_real_escape_string($dbc, trim($_POST['initiala_tatalui']));
}

// Check for a last name:
if (empty($_POST['prenumele'])) {
    $errors[] = 'Câmpul Prenumele este gol !';
} else {
    $pre = mysqli_real_escape_string($dbc, trim($_POST['prenumele']));
}

    // Check for a previous name:
//if (empty($_POST['numele_anterior'])) {
//  $errors[] = 'Câmpul Numele Anterior este gol !';
//} else {
    $nan = mysqli_real_escape_string($dbc, trim($_POST['numele_anterior']));
//}

    $sex = mysqli_real_escape_string($dbc, trim($_POST['sex']));

    // Check CNP:
if (empty($_POST['cnp'])) {
    $errors[] = 'Câmpul CNP este gol !';
} else {
    $cnp = mysqli_real_escape_string($dbc, trim($_POST['cnp']));
}

// Check for an email address:
if (empty($_POST['adresa_email'])) {
    $errors[] = 'Câmpul Adresa Email este gol !';
} else {
    $aem = mysqli_real_escape_string($dbc, trim($_POST['adresa_email']));
}

    // Check for a speciality2:
//if (empty($_POST['specialitate2'])) {
//  $errors[] = 'Ați uitat sa introduceți Specialitate 2.';
//} else {

    $speci2 = mysqli_real_escape_string($dbc, trim($_POST['specialitate2']));
            $an_abs_univ = mysqli_real_escape_string($dbc, trim($_POST['an_abs_univ']));
            $seria_dipl_univ = mysqli_real_escape_string($dbc, trim($_POST['seria_dipl_univ']));
            $nr_dipl_univ = mysqli_real_escape_string($dbc, trim($_POST['nr_dipl_univ']));
            $stare = mysqli_real_escape_string($dbc, trim($_POST['stare']));
            $cod_parafa = mysqli_real_escape_string($dbc, trim($_POST['cod_parafa']));
            $first_name = $_POST['first_name'];
            $user_id = $_POST['user_id'];
            $cm_nr = mysqli_real_escape_string($dbc, trim($_POST['cm_nr']));
            $cm_data_elib = mysqli_real_escape_string($dbc, trim($_POST['cm_data_elib']));
//}

    // Validate the university...
//if ( isset($_POST['universit']) && filter_var($_POST['universit'], FILTER_VALIDATE_INT, array('min_range' => 1))  ) {
//  $univ = $_POST['universit'];
//} else { // No artist selected.
//  $errors[] = 'Vă rugăm selectați Universitatea !';
//}

if (empty($errors)) { // If everything's OK.

    //  Test for unique email address:
    $q = "SELECT medic_id FROM medici WHERE adresa_email='$aem' AND medic_id != $id";
    $r = @mysqli_query($dbc, $q);
    if (mysqli_num_rows($r) == 0) {
            //  Test for unique CNP:
    $q = "SELECT medic_id FROM medici WHERE cnp='$cnp' AND medic_id != $id";
    $r = @mysqli_query($dbc, $q);
    if (mysqli_num_rows($r) == 0) {

        // Make the query:
        $q = "UPDATE medici SET numele='$num', initiala_tatalui='$ita', prenumele='$pre', numele_anterior='$nan', cnp='$cnp', adresa_email='$aem', stare='$stare', cod_parafa='$cod_parafa', specialitate2='$speci2', an_abs_univ='$an_abs_univ', seria_dipl_univ='$seria_dipl_univ', nr_dipl_univ='$nr_dipl_univ',  cm_nr='$cm_nr', cm_data_elib='$cm_data_elib', data_modificarii=NOW(), first_name='$first_name', user_id='$user_id', first_name_mod='{$_SESSION['first_name']}', user_id_mod='{$_SESSION['user_id']}' WHERE medic_id=$id LIMIT 1";//LIMIT 1
        $r = @mysqli_query ($dbc, $q);
        if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

            // Print a message:
            echo '<p><font color="red"><b>Datele Medicului au fost modificate.</b></font></p>'; 

        } else { // If it did not run OK.
            echo '<p class="error">Medicul nu a fost modificat ca urmare a unei erori de sistem.</p>'; // Public message.
            echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
        }
    } else { // Already registered.
        echo '<p class="error">CNP a fost deja înregistrat.</p>';
    }       
    } else { // Already registered.
        echo '<p class="error">Adresa de email a fost deja înregistrată.</p>';
    }

} else { // Report the errors.

    echo '<p class="error">The following error(s) occurred:<br />';
    foreach ($errors as $msg) { // Print each error.
        echo " - $msg<br />\n";
    }
    echo '</p><p>Vă rugăm încercați din nou.</p>';

} // End of if (empty($errors)) IF.

} // End of submit conditional.

// Always show the form...

// Retrieve the doctor's information:
$q = "SELECT universitate, numele, initiala_tatalui, prenumele, numele_anterior, sex, cnp, adresa_email, specialitate, specialitate2, an_abs_univ, seria_dipl_univ, nr_dipl_univ, first_name, user_id, data_adaugarii, first_name_mod, user_id_mod, stare, cod_parafa, cm_nr, cm_data_elib, data_modificarii FROM adm, medici, adm1 WHERE adm.adm_id=medici.adm_id AND adm1.adm1_id=medici.adm1_id AND medic_id=$id";       
$r = @mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

// Get the user's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);

// Create the form:

echo '<form action="edit_medic.php" method="post">
<fieldset>
<p><font color="green"><b>Informații Personale:</b></font></p>
<p>Numele: <input type="text" name="numele" size="15" maxlength="15" value="' . $row[1] . '" />&nbsp;&nbsp;&nbsp;
Initiala tatalui: <input type="text" name="initiala_tatalui" size="15" maxlength="15" value="' . $row[2] . '" />&nbsp;&nbsp;&nbsp;
Prenumele: <input type="text" name="prenumele" size="15" maxlength="30" value="' . $row[3] . '" /></p>
<p>Numele Anterior: <input type="text" name="numele_anterior" size="15" maxlength="15" value="' . $row[4] . '" /></p>
<p>SEX: <input type="text" readonly name="sex" size="1" maxlength="1" value="' . $row[5] . '" /></p>
<p>CNP: <input type="text" name="cnp" size="15" maxlength="15" value="' . $row[6] . '" /></p>
<p>Adresa Email: <input type="text" name="adresa_email" size="50" maxlength="50" value="' . $row[7] . '"  /> </p>

<hr>
<p><font color="green"><b>Informații Medic:</b></font></p>
<p>Stare: <input type="text" readonly name="stare" size="25" maxlength="25" value="' . $row[18] . '"  /> 
&nbsp;Modifică în:<input type="radio" name="stare" value="Public" />Public <input type="radio" name="stare" value="Privat" />Privat <input type="radio" name="stare" value="Public + Privat" />Public + Privat <input type="radio" name="stare" value="Nu lucrează" />Nu lucrează <input type="radio" name="stare" value="Transferat RO" />Transferat RO <input type="radio" name="stare" value="Transferat Străinatate" />Transferat Străinătate <input type="radio" name="stare" value="Pensionar" />Pensionar <input type="radio" name="stare" value="Pensionar Public" />Pensionar Public <input type="radio" name="stare" value="Pensionar Privat" />Pensionar Privat <input type="radio" name="stare" value="Decedat" />Decedat</p>
<p>Cod Parafă: <input type="text" name="cod_parafa" size="10" maxlength="10" value="' . $row[19] . '" /></p>

<hr>
<p><font color="green"><b>Studii și Specializări:</b></font></p>

<p>Universitatea: <input type="text" readonly name="universit" size="50" maxlength="50" value="' . $row[0] . '" />&nbsp;&nbsp;&nbsp;
An Absolvire: <input type="text" name="an_abs_univ" size="4" maxlength="4" value="' . $row[10] . '"  />&nbsp;&nbsp;&nbsp;
Serie Diplomă: <input type="text" name="seria_dipl_univ" size="3" maxlength="3" value="' . $row[11] . '"  />&nbsp;&nbsp;&nbsp;
Nr. Diplomă: <input type="text" name="nr_dipl_univ" size="10" maxlength="10" value="' . $row[12] . '"  /></p>

<p>Specialitate 1: <input type="text" readonly name="specialitate" size="50" maxlength="50" value="' . $row[8] . '"  />
&nbsp;Modifică în:      
 <input type="text" name="specialitate" size="50" maxlength="50" value="' . $row[8] . '"  />

 </p>
<p>Specialitate 2: <input type="text" name="specialitate2" size="50" maxlength="50" value="' . $row[9] . '"  /></p>

<hr>
<p><font color="green"><b>Certificat de Membru</b></font></p>
<p><b>Nr. Certificat:</b> <input type="text" name="cm_nr" size="5" maxlength="5" value="' . $row[20] . '"  />
<b>Data Eliberării:</b>&nbsp; <input type="text" name="cm_data_elib" size="10" maxlength="10" value="' . $row[21] . '"  />
<hr>
<p><font color="green"><b>Evidență Adăugiri și Modificări:</b></font></p>
<p>Adăugat de: <input type="text" readonly name="first_name" size="50" maxlength="50" value="' . $row[13] . '"  />
User ID: <input type="text" readonly name="user_id" size="5" maxlength="5" value="' . $row[14] . '"  />
La data de: <input type="text" readonly name="data_adaugarii" size="15" maxlength="15" value="' . $row[15] . '"  />
<p>Modificat de: <input type="text" readonly name="first_name_mod" size="50" maxlength="50" value="' . $row[16] . '"  />
User ID: <input type="text" readonly name="user_id_mod" size="5" maxlength="5" value="' . $row[17] . '"  />
La data de: <input type="text" readonly name="data_modificarii" size="15" maxlength="15" value="' . $row[22] . '"  />
<p>Acum modifică: <input type="text" readonly name="first_name_mod" size="50" maxlength="50" value="'.$_SESSION['first_name'].'"  />
User ID: <input type="text" readonly name="user_id_mod" size="5" maxlength="5" value="'.$_SESSION['user_id'].'"  /></p>


</fieldset>
<p></p>
<p><div align="center"><input type="submit" name="submit" value="Modifică" /></p>
<input type="hidden" name="id" value="' . $id . '" />
</form>';
    echo '<form method="post" action="lista_medici.php">
<input type="submit" value="Înapoi"></div>
</form>';

} else { // Not a valid user ID.
echo '<p class="error">This page has been accessed in error2.</p>';
}

mysqli_close($dbc);

//aici e 2 cu cel de sus, adika daca nu e logat nu are acces la baza de date
} else { //  Not logged in.
    echo '<br><a href="register.php" title="Înregistrare nouă">Înregistrare nouă</a><br />
<a href="login.php" title="Autentificare">Autentificare</a><br />
<a href="forgot_password.php" title="Recuperare Parolă">Recuperare Parolă</a><br />
';
}

include ('includes/footer.html');
?>
4

4 回答 4

0

您的问题似乎与数据库或下拉菜单无关,只是基本的 PHP 语法。

从 PHP 输出 HTML 有多种方式;简化一点:

  • <?php ... ?>输出包装器之外的任何文本。所以在你的第一个文件中,你必须?><form ...>输出一个表单,当你想要更多的 PHP 时,你重新打开<?php.
  • echo语句输出字符串表达式 - 变量、函数或带引号的字符串。所以在你的第二个文件中,你有echo '<form...并且字符串一直持续到匹配',用;标记结束echo

在您尝试的代码中,您将两者混合在一起:您仍在以 a 开头的字符串中',但您粘贴了 a <?php。这行不通。

您需要做的就是拥有多个echo,因此您可以结束echo '...';然后重新开始:

echo '<form action="edit_doctor.php" method="post">
... 
<select name="universit"><option>Selectează</option>';
// Retrieve all the artists and add to the pull-down menu.
$q = "SELECT adm_id, CONCAT_WS(' ', universitate) FROM adm ORDER BY universitate ASC";      
$r = mysqli_query ($dbc, $q);
// ...
mysqli_close($dbc); // Close the database connection.
echo '
...
</fieldset>
...
</form>';
于 2013-09-28T04:14:57.900 回答
0

你能试试这个并使用相同的表单代码吗?

if (mysqli_num_rows($r) == 1) 
{
    $action = "edit_doctor.php";
}
else
{
    $action = "add_doctor.php";
}

echo '<form action="$action" method="post">';
于 2013-09-28T04:16:59.363 回答
0
<?php
// Retrieve the doctor's information:
$q = "SELECT universitate, numele, initiala_tatalui, prenumele, numele_anterior, sex, cnp, adresa_email, specialitate, specialitate2, an_abs_univ, seria_dipl_univ, nr_dipl_univ, first_name, user_id, data_adaugarii, first_name_mod, user_id_mod, stare, cod_parafa, data_modificarii FROM adm, medici, adm1 WHERE adm.adm_id=medici.adm_id AND adm1.adm1_id=medici.adm1_id AND medic_id='".$id."'";        
$r = @mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

// Get the doctor's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);

// Create the form:
?>
<form action="edit_doctor.php" method="post">
<fieldset>
<p><font color="green"><b>Studii și Specializări:</b></font></p> 

<p><b>Universitatea:</b> 
<select name="universit"><option>Selectează</option>
<?php // Retrieve all the artists and add to the pull-down menu.
$q = "SELECT adm_id, CONCAT_WS(' ', universitate) FROM adm ORDER BY universitate ASC";      
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) > 0) {
    while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
        ?>
   <option value="<?php echo $row[0];?>" <?php if (isset($_POST['universit']) && ($_POST['universit'] == $row[0]) ){ echo ' selected="selected"'; }?>>
   <?php echo $row[1];?>
   </option>
   <?php }
} else {
    echo '<option>Vă rugăm adăugați o Universitate prima dată.</option>';
}
mysqli_close($dbc); // Close the database connection.
?>
...
</fieldset>
<p></p>
<p><div align="center"><input type="submit" name="submit" value="Modifică" /></p>
<input type="hidden" name="id" value="<?php echo $id;?>" />
</form>
于 2013-09-28T04:32:51.947 回答
0
Hi You try this code..
I can't understand what you want? You have any queries tell me.
// Retrieve the doctor's information:
<form action="edit_doctor.php" method="post">
<fieldset>
<p><font color="green"><b>Studii și Specializări:</b></font></p>

<?php 
$q = "SELECT universitate, numele, initiala_tatalui, prenumele, numele_anterior, sex, cnp, adresa_email, specialitate, specialitate2, an_abs_univ, seria_dipl_univ, nr_dipl_univ, first_name, user_id, data_adaugarii, first_name_mod, user_id_mod, stare, cod_parafa, data_modificarii FROM adm, medici, adm1 WHERE adm.adm_id=medici.adm_id AND adm1.adm1_id=medici.adm1_id AND medic_id=$id";        
$r = @mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.

// Get the doctor's information:
while($row = mysqli_fetch_array ($r, MYSQLI_NUM))
{?>

// Create the form:
<input type="hidden" name="id" value="<?php echo $id;?>" />
<p>Universitatea: <input type="text" readonly name="universit" size="50" maxlength="50" value="<?php echo $row[0]; ?>" />

<?php }}?>

</fieldset>
<p></p>
<p><div align="center"><input type="submit" name="submit" value="Modifică" /></p>

</form>
于 2013-09-28T04:12:41.753 回答