dshdb64088 2014-06-21 04:54
浏览 13

通过php向数据库添加细节

I have a code through which an employee can apply for leave and the details of the leave should be stored in the database. The details also include 2 images i.e empsign and empdate and the rest of the details are in text.

<?php
    require_once('config.php'); //connection to database
    $empname = $_REQUEST['empname']; //no default
    $empid = $_REQUEST['empid']; //no default
    $deptt = $_REQUEST['deptt']; //no default
    $noofdays = $_REQUEST['noofdays']; //no default
    $from = $_REQUEST['from']; //no default
    $to = $_REQUEST['to']; //no default
    $morning = $_REQUEST['morning']; //no default
    $afternoon = $_REQUEST['afternoon']; //no default
    $reasonemp = $_REQUEST['reasonemp']; //no default
    $contactaddr= $_REQUEST['contactaddr']; //no default
    $phoneno = $_REQUEST['phoneno']; //no default
    $empsign = $_REQUEST['empsign']; //no default
    $empdate= $_REQUEST['empdate']; //no default

    $filename = $_REQUEST['empsign']; //no default
    $buffer=base64_decode($filename);
    $path = "empsign/image".$date.".jpg";
    $path1 = "http://example.com/employee/empsign/image".$date.".jpg";
    $handle = fopen($path, 'wb');
    $numbytes = fwrite($handle, $buffer);
    fclose($handle);

    $filename= $_REQUEST['empdate']; //no default
    $buffer=base64_decode($filename);
    $path = "empdate/image".$date.".jpg";
    $path1 = "http://example.com/employee/empdate/image".$date.".jpg";
    $handle = fopen($path, 'wb');
    $numbytes = fwrite($handle, $buffer);
    fclose($handle);

    $inserts = mysqli_query(
        "insert into 
        approveleave (empname,empid,deptt,noofdays,from,to,morning,afternoon,reasonemp,contactaddr,phoneno,empsign,empdate)
        values ('".$empname."','".$empid."','".$deptt."','".$noofdays."','".$from."','".$to."','".$morning."','".$afternoon."','".$reasonemp."','".$contactaddr."','".$phoneno."','".$empsign."','".$empdate."')"
        );

    $posts[0]['message'] = 'leave applied';
    $idd = mysqli_insert_id();
    $selectt = mysqli_query("select * from approveleave where id = '".$idd."'");
    $results =  mysqli_fetch_assoc($selectt);
    $posts[0]['detail'] = $results;
    header('Content-type: application/json');
    echo json_encode($posts);
?>

The problem is that when i run this code no value is being stored in the database and the error that i am getting is

[{"message":"employee added","detail":false}]

Can please anyone help me?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动