需要帮助将 ID 写入 MySQL 数据库

发布于 2024-11-09 11:13:39 字数 3622 浏览 0 评论 0原文

我正在尝试将另一个 MySQL 表中已存在的 ID 写入第二个 MySQL 表,我在下拉菜单中回显该 ID 以及与该 ID 关联的名称。

这是源代码:

<div id="postedit" class="clearfix">
            <h2 class="ico_mug">Legg ansatte!</h2>
            <form name="form1" method="post" action="<?($_SERVER['DOCUMENT_ROOT']."/ansatte.php")?>">
            <div><input name="navn" type="text" size="30" tabindex="1" value="Skriv navn!" /></br></br>
            <div id="form_middle_cont" class="clearfix">
            <input name="telefon" type="text" size="30" tabindex="1" value="Skriv inn telefon nummer!" /></br></br>
            <input name="mobil" type="text" size="30" tabindex="1" value="Skriv inn mobiltelefon nummer!" /></br></br>
            <input name="epost" type="text" size="30" tabindex="1" value="Skriv inn epost nummer!" /></br></br>
            <input name="bilde" type="text" size="30" tabindex="1" value="Skriv inn link til bilde!" /></br></br>
            </div>
                <h3>Possisjon: </h3>
        <select name="Possisjon" id="possisjon">

        <?PHP   // Generate a drop-down list of sections.

                $result = $connector->query('SELECT position_name FROM position ORDER BY position_id');

                // Get an array containing the results.
                // Loop for each item in that array
                while ($row = $connector->fetchArray($result)){
                    echo '<option value="'.$row['position_id'].'">'.$row['position_name'].'</option>';
                }
          ?>
        </select></br></br>

        <h3>Stilling:</h3>
        <input name="stilling" type="text" size="30" tabindex="1" /></br></br>



          <input type="submit" name="Lagre" value="Submit">

            </div>
            </form>
<?php
// Create an instance of DbConnector
$connector = new DbConnector();

// Setter alt inn i databasen

if($_POST) {

$navn = $_POST['navn'];
$telefon = $_POST['telefon'];
$mobil = $_POST['mobil'];
$epost = $_POST['epost'];
$image = $_POST['bilde'];
$stilling = $_POST['stilling'];
$position = $_POST['possisjon'];

if($navn == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Angi en tittel!</span></div><br>';
if($mobil == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Angi mer en én tag!</span></div><br>';
if($epost == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Velg en seksjon!</span></div><br>';
if($image == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Oida! Du har ikke skrevet noe innhold i artikkelen, prøv igjen!</span></div><br><br>';
if($position == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">lalalala</span></div><br><br>';

if($navn != '' && $telefon != '' && $mobil != '' && $epost != '' && $image != '' && $stilling != '' && $possisjon !='') {
mysql_query("INSERT INTO ansatte (navn, telefon, mobil, epost, image, stilling) VALUES ('{$navn}', '{$telefon}', '{$mobil}', '{$epost}', '{$bilde}', '{$stilling}', '{$possisjon}')");
echo '<div id="success" class="info_div"><span class="ico_success">Suksess!</span></div>';
}


}
?>

有人有什么想法吗?

干杯, ~纯粹的黑暗~

I am trying to write an ID that already exists in a different MySQL table to a second MySQL table, I am echoing the ID and the name associated to the ID in a dropdown menu.

Here is the sourcecode:

<div id="postedit" class="clearfix">
            <h2 class="ico_mug">Legg ansatte!</h2>
            <form name="form1" method="post" action="<?($_SERVER['DOCUMENT_ROOT']."/ansatte.php")?>">
            <div><input name="navn" type="text" size="30" tabindex="1" value="Skriv navn!" /></br></br>
            <div id="form_middle_cont" class="clearfix">
            <input name="telefon" type="text" size="30" tabindex="1" value="Skriv inn telefon nummer!" /></br></br>
            <input name="mobil" type="text" size="30" tabindex="1" value="Skriv inn mobiltelefon nummer!" /></br></br>
            <input name="epost" type="text" size="30" tabindex="1" value="Skriv inn epost nummer!" /></br></br>
            <input name="bilde" type="text" size="30" tabindex="1" value="Skriv inn link til bilde!" /></br></br>
            </div>
                <h3>Possisjon: </h3>
        <select name="Possisjon" id="possisjon">

        <?PHP   // Generate a drop-down list of sections.

                $result = $connector->query('SELECT position_name FROM position ORDER BY position_id');

                // Get an array containing the results.
                // Loop for each item in that array
                while ($row = $connector->fetchArray($result)){
                    echo '<option value="'.$row['position_id'].'">'.$row['position_name'].'</option>';
                }
          ?>
        </select></br></br>

        <h3>Stilling:</h3>
        <input name="stilling" type="text" size="30" tabindex="1" /></br></br>



          <input type="submit" name="Lagre" value="Submit">

            </div>
            </form>
<?php
// Create an instance of DbConnector
$connector = new DbConnector();

// Setter alt inn i databasen

if($_POST) {

$navn = $_POST['navn'];
$telefon = $_POST['telefon'];
$mobil = $_POST['mobil'];
$epost = $_POST['epost'];
$image = $_POST['bilde'];
$stilling = $_POST['stilling'];
$position = $_POST['possisjon'];

if($navn == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Angi en tittel!</span></div><br>';
if($mobil == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Angi mer en én tag!</span></div><br>';
if($epost == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Velg en seksjon!</span></div><br>';
if($image == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">Oida! Du har ikke skrevet noe innhold i artikkelen, prøv igjen!</span></div><br><br>';
if($position == '')
echo '<div id="fail" class="info_div"><span class="ico_cancel">lalalala</span></div><br><br>';

if($navn != '' && $telefon != '' && $mobil != '' && $epost != '' && $image != '' && $stilling != '' && $possisjon !='') {
mysql_query("INSERT INTO ansatte (navn, telefon, mobil, epost, image, stilling) VALUES ('{$navn}', '{$telefon}', '{$mobil}', '{$epost}', '{$bilde}', '{$stilling}', '{$possisjon}')");
echo '<div id="success" class="info_div"><span class="ico_success">Suksess!</span></div>';
}


}
?>

Any ideas anyone?

Cheers,
~ PureDarkness ~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-11-16 11:13:39

现在更改您的查询

$result = $connector->query('SELECT position_name,position_id 
                            FROM position 
                            ORDER BY position_id');

,您可以在以下代码中使用position_id

change your query

$result = $connector->query('SELECT position_name,position_id 
                            FROM position 
                            ORDER BY position_id');

now you can use the position_id in your following code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文