mysql/androidstudio,表上的列仅接受 int,而不接受 varchar

我正在尝试在表中插入行,但是列“department”只接受整数。 我使用此教程作为我的指南。

如果我将第四列(部门)的类型更改为 int 并在其上插入 int ,则一切正常。但我需要绳子。我已经将所述列的类型更改为 VARCHAR 但始终显示“0”在桌子上,即使我插入一个字符串。

我的桌子

https://img1.sycdn.imooc.com/657bf9be00018e9d05730129.jpg

这是我的表结构

https://img1.sycdn.imooc.com/657bf9c700010f2606510151.jpg

API.php


<?php 

require_once '../includes/DbOperation.php';

function isTheseParametersAvailable($params){

    $available = true; 

    $missingparams = ""; 

    

    foreach($params as $param){

        if(!isset($_POST[$param]) || strlen($_POST[$param])<=0){

            $available = false; 

            $missingparams = $missingparams . ", " . $param; 

        }

    }

    if(!$available){

        $response = array(); 

        $response['error'] = true; 

        $response['message'] = 'Parameters ' . substr($missingparams, 1, strlen($missingparams)) . ' missing';

        echo json_encode($response);

                die();

    }

}


$response = array();


if(isset($_GET['apicall'])){

    

    switch($_GET['apicall']){

        

        //the CREATE operation

        //if the api call value is 'createhero'

        //we will create a record in the database

        case 'createemployee':

            //first check the parameters required for this request are available or not 

            isTheseParametersAvailable(array('firstname','lastname','department','image'));

            

            //creating a new dboperation object

            $db = new DbOperation();

            

            //creating a new record in the database

            $result = $db->createEmployee(

                $_POST['firstname'],

                $_POST['lastname'],

                $_POST['department'],

                $_POST['image']

            

    

            );

            

            }

            

        break; 


摇曳的蔷薇
浏览 45回答 1
1回答

一只名叫tom的猫

$stmt->bind_param("ssis",&nbsp;$firstname,&nbsp;$lastname,&nbsp;$department,&nbsp;$image);使用&nbsp;中的&nbsp;i,您指定此处的第三个插入值应该是整数,因此它会被视为整数,其中包括转换无效值为零。ssis
打开App,查看更多内容
随时随地看视频慕课网APP