需要帮助将 ID 写入 MySQL 数据库
我正在尝试将另一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在更改您的查询
,您可以在以下代码中使用position_id
change your query
now you can use the position_id in your following code