将数据从我的表单发送到SQL数据库

时间:2019-03-15 02:21:50

标签: php sql

最后一个变量$type有点问题。我不确定自己在做什么错。它可以正确显示所有内容,但保存时不会将其写回到数据库中。如果删除对变量“ $ type”的任何引用,那么我的表单就可以写到数据库了。以下是与我的问题有关的代码段。

if(isset($_POST['update-project']))
{
   $flag=0;
   if($flag==0)
   {
     $s_idsa    = implode(',', $_POST['staff']);
     $pp_id     = $pro_id;
     $pp_title  = $_POST['projectTite'];
     $pc_id     = $_POST['client'];
     $ps_ids    = $s_idsa;
     $pp_desc   = $_POST['description'];
     $p_budget  = $_POST['budget'];
     $p_status  = $_POST['status'];
     $p_archive = $_POST['archive'];
     $ps_time   = $_POST['startTime'];
     $pe_time   = $_POST['endTime'];
     $type      = $_POST['type'];

     $sql_up = "UPDATE `projects` SET `c_id`='$pc_id', `s_ids`='$ps_ids', `project_title`='$pp_title', `project_desc`='$pp_desc', `budget`='$p_budget',    `status`='$p_status', `archive`='$p_archive', `start_time`='$ps_time',    `end_time`='$pe_time','proj_type'='$type' WHERE `p_id`='$pp_id'";


if ($connect->query($sql_up) === TRUE)
                {
header("Location:projects.php?message=success");
                }
                else
                {
header("Location:projects.php?message=fail");
                }
$connect->close(); 


     <div class="form-group">
        <select class="ui dropdown form-control" name="type" id="hidden" required>
            <option value="">Select a Project Type</option>
            <option value="1"<?php if($proj_type == 1){ ?> selected <?php } ?>>Without Invoicing</option>
            <option value="2"<?php if($proj_type == 2){ ?> selected <?php } ?>>With Invoicing</option>
        </select>
     </div>

1 个答案:

答案 0 :(得分:0)

我知道了。

"'proj_type'='$type'" //needs backticks instead of single quotes. doh.