从下拉菜单中选择id所选名称

时间:2013-09-13 07:34:54

标签: php

我想在数据库中插入plan_id,其中plan_name =(从select中选择)

你可以帮我弄清楚这个片段中的错误吗

<?php
$plan_id = ($a);
$query = "INSERT INTO tbl_reservation(cust_id, pack_type, plan_id, res_date, res_venue,     date_app) VALUES     ('{$cust_id}','{$pack_type}','{$plan_id}','{$res_date}','{$res_venue}',CURDATE())";
$result_set = mysql_query($query);
?>
<select name="plan_id">
<?php 
    $queryy = mysql_query("SELECT * FROM tbl_wed_plan");
    while ($row = mysql_fetch_array($queryy)){
    $plan_id = $row['plan_id'];

    echo"<option value='.$row[plan_name].'>$row[plan_name]</option>";
    }

    $a = '';
    if('plan_id' == 'Sho Minamimoto') {
    $a = 'plan-01';
    }else if('plan_id' == 'Janine Tugonon') {
    $a = 'plan-02';
    }else if('plan_id' == 'Jessie Jameson') {
    $a = 'plan-03';
    }else if('plan_id' == 'Karl Marx Bautista') {
    $a = 'plan-04';
    }
?>

2 个答案:

答案 0 :(得分:0)

以下是更正后的代码: 用户$plan_id代替'plan_id'

<?php
$plan_id = ($a);
$query = "INSERT INTO tbl_reservation(cust_id, pack_type, plan_id, res_date, res_venue,     date_app) VALUES     ('{$cust_id}','{$pack_type}','{$plan_id}','{$res_date}','{$res_venue}',CURDATE())";
$result_set = mysql_query($query);

<?php 
    $queryy = mysql_query("SELECT * FROM tbl_wed_plan");
    while ($row = mysql_fetch_array($queryy)){
    $plan_id = $row['plan_id'];

    echo"<option value='".$plan_id."'>".$row['plan_name']."</option>";
    }

    $a = '';
    if($plan_id == 'Sho Minamimoto') {
    $a = 'plan-01';
    }else if($plan_id == 'Janine Tugonon') {
    $a = 'plan-02';
    }else if($plan_id == 'Jessie Jameson') {
    $a = 'plan-03';
    }else if($plan_id == 'Karl Marx Bautista') {
    $a = 'plan-04';
    }
?>

答案 1 :(得分:0)

连接问题..我想

echo"<option value='".$plan_id."'>".$row[plan_name]."</option>";