-2

我正在尝试创建一个表单,该表单需要检索有关员工的信息,然后员工输入他们的费用报销。检索数据的过程正常工作,但它没有将输入的费用报销数据保存到数据库中。

如果有人可以帮助我,我将不胜感激。

这是我的代码。

<?php
session_start();

if($_SESSION['emp_no']){
echo "Welcome, ".$_SESSION['emp_no']."!";
}
 else 
 die("You must enter your employee no. ");

$connect = mysql_connect("localhost","root","Omaima2010") or die ("Could not connect");

mysql_select_db("expenses") or die ("Could not find the data base");

$emp_no= $_SESSION['emp_no'];

$query = mysql_query("select e.emp_no, e.manager_no, e.emp_name, m.manager_no, m.manager_name, m.dept_name 
from employee e , manager m
where emp_no = '$emp_no' and e.manager_no = m.manager_no");
while($query1 = mysql_fetch_array($query)){
$emp_no = $query1['emp_no'];
$emp_name = $query1 ['emp_name'];
$manager_name = $query1 ['manager_name'];
$manager_no = $query1 ['manager_no'];
$dept_name = $query1 ['dept_name'];
}


    if(isset($_POST['exp_desc'])){

      //This is the directory where vouchers will be saved 
     $target = "vouchers/"; 
     $target = $target .basename( $_FILES['datafile']['name']); 

    $exp_desc = $_POST['exp_desc'];
    $date = (date ("d/m/Y"));
    $receipt = $_FILES['datafile']['name'];
    $amount = $_POST['amount'];
    $exch_rate= ($_POST['exch_rate']);
    $bd = ($_POST['BD']);

     mysql_query("INSERT INTO expenses_claim(emp_no,manager_no,exp_desc,claimant_date,amount,exch_rate,BD,receipt) VALUES ('$emp_no','$manager_no','$exp_desc','$date','$amount','$exch_rate','$bd','$receipt',now())");

    //Writes the file to the server 
    if(move_uploaded_file($_FILES['datafile']['tmp_name'], $target)) 
    { 

     //Tells you if its all ok 
     echo "The file " . basename( $_FILES['datafile']['name']). " has been uploaded"; 


     } 
     else { 

    //Gives and error if its not 
    echo "Sorry, there was a problem uploading your file."; 
     } 
    }


?>
4

2 回答 2

1

您的查询中有 8 列和 9 个值,只需删除,now()

于 2013-09-29T11:40:40.317 回答
0
  1. 使用准备好的语句。从 PHP 5.5 开始,mysql_query 也被贬低了,所以你应该切换到 mysqli 或 PDO。

  2. 验证您的输入。我敢打赌,您的问题是输入错误导致查询失败的结果。

  3. 如果您发送的查询可能会失败,请确保捕获您的错误。例如:

    if(!mysql_query($query))
         echo "Your query failed.  It consisted of: $query and the error was " .   mysql_error();
    
于 2013-09-29T11:40:24.793 回答