我如何使用张贴的数字id从数据库中获取类别的值


How do I fetch value of category from database using posted numeric id

首先,请原谅我对PHP非常陌生。我是牙医的招聘人员我有一张让候选人在网上填写的表格。

我创建了4个mysql表,其中包含学科,类型买家,过渡时间和毕业年份的信息。这允许我一次更改选项,而不是在我的网站上的多个页面上这样做。

您可以在http://www.missouridentalpracticeforsale.com/indexnewbjs.php

看到表单

当提交表单时,我让它正确地将数据库中的数据转储到我创建的数据库表中。但是,我有一封电子邮件,每次我得到一个新的潜在客户时都会发送给我,对于在这些表中创建的字段,我只获得ID值,我需要获得与ID相关联的内容。

交货。而不是去看牙医,我得到1的值而不是得到正畸医生买家类型的买家,我得到#3

下面是索引页和表单提交页的代码

---------- 很小一部分的代码2字段纪律和类型买家 --------------

<tr>
<td>Discipline:</td>
<td><select name="disc" class="tableappointdata" id="disc">
<?php $discpfs_sql = 'SELECT id, disc FROM discpfs WHERE id >= 0'; $discpfs_res =       sql_query($discpfs_sql,$leads_db); while($discpfs = mysql_fetch_array($discpfs_res)){ echo '<option value="' . $discpfs['id'] . '">' . $discpfs['disc'] . '</option>'; } ?>
                      </select>                      </td>
                    </tr>
                    <tr>
                      <td>Type Buyer:</td>
                      <td><select name="typebuy" class="tableappointdata" id="typebuy">
                        <?php $typebuy_sql = 'SELECT id, typebuy FROM typebuy WHERE id >= 0'; $typebuy_res = mysql_query($typebuy_sql,$leads_db); while($typebuy = mysql_fetch_array($typebuy_res)){ echo '<option value="' . $typebuy['id'] . '">' . $typebuy['typebuy'] . '</option>'; } ?>
                      </select>                      </td>
                    </tr>
-------------------------------Form Submittal Code------------------------------------
            $msg  .= 'Name: ' . $_POST['first_name'] . ' ' . $_POST['last_name'] . '<br   />' . "'r'n";
        $msg  .= 'Discipline: ' . $_POST ['disc']  . '<br />' . "'r'n";
        $msg  .= 'Type Buyer: ' . $_POST['typebuy']  . '<br />' . "'r'n";
        $msg  .= 'Transition Time: ' . $_POST['transtime']  . '<br />' . "'r'n";
        $msg  .= 'Practice Type Desired: ' . $_POST['desire']  . '<br />' . "'r'n";
        $msg  .= 'Practice Size Wanted: ' . $_POST['practsize']  . '<br />' . "'r'n";
        $msg  .= 'Number of Ops: ' . $_POST['numberops']  . '<br />' . "'r'n";
        $msg  .= 'Graduation Year: ' . $_POST['grad']  . '<br />' . "'r'n";
        $msg  .= 'City: ' . $_POST['city']  . '<br />' . "'r'n";
        $msg  .= 'State: ' . $_POST['state']  . '<br />' . "'r'n";
        $msg  .= 'Zip: ' . $_POST['zip']  . '<br />' . "'r'n";

我知道这可能是一个非常简单的修复,但是我要疯了,试图弄清楚我如何从我的电子邮件中显示单词而不是相应的ID号码表。

任何帮助都将非常感激。

谢谢

错误如下。

echo '<option value="' . $discpfs['id'] . '">' . $discpfs['disc'] . '</option>';

您正在显示select选项上的实际内容,但是表单的POST方法发送的是"value"字段,即$discpfs['id']。

你有两个选项,如果你在提交表单后不使用id,你可以在"value"字段发送实际内容

echo '<option value="' . $discpfs['disc'] . '">' . $discpfs['disc'] . '</option>';

但是如果您使用id,您可以使用id进行另一个查询,并使用查询检索到的值构建字符串$msg

使用如下查询:

$discpfs_sql = 'SELECT id, disc FROM discpfs WHERE id ='. $_POST['disc'];

请使用以下代码。

    $disc_id=$_POST ['disc'];
    $discpfs_sql = mysql_query("SELECT disc FROM discpfs WHERE id = '$disc_id'");
    $disc=mysql_fetch_array($discpfs_sql);
    $type_id=$_POST ['typebuy'];
    $typebuy_sql = mysql_query("SELECT typebuy FROM typebuy WHERE id = '$type_id'");
    $typebuy=mysql_fetch_array($typebuy_sql);
    $msg  .= 'Name: ' . $_POST['first_name'] . ' ' . $_POST['last_name'] . '<br   />' . "'r'n";
    $msg  .= 'Discipline: ' . $disc['disc']  . '<br />' . "'r'n";
    $msg  .= 'Type Buyer: ' . $typebuy['typebuy']  . '<br />' . "'r'n";
    $msg  .= 'Transition Time: ' . $_POST['transtime']  . '<br />' . "'r'n";
    $msg  .= 'Practice Type Desired: ' . $_POST['desire']  . '<br />' . "'r'n";
    $msg  .= 'Practice Size Wanted: ' . $_POST['practsize']  . '<br />' . "'r'n";
    $msg  .= 'Number of Ops: ' . $_POST['numberops']  . '<br />' . "'r'n";
    $msg  .= 'Graduation Year: ' . $_POST['grad']  . '<br />' . "'r'n";
    $msg  .= 'City: ' . $_POST['city']  . '<br />' . "'r'n";
    $msg  .= 'State: ' . $_POST['state']  . '<br />' . "'r'n";
    $msg  .= 'Zip: ' . $_POST['zip']  . '<br />' . "'r'n";