Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQLi未在此程序中更新如何解决此错误_Php_Html_Mysqli - Fatal编程技术网

Php MySQLi未在此程序中更新如何解决此错误

Php MySQLi未在此程序中更新如何解决此错误,php,html,mysqli,Php,Html,Mysqli,此代码是一个字段问题。文件的格式为int,而值的格式为varchar。那么如何更改联接查询 <?php include 'dblayer.php'; $action = isset( $_POST['action'] ) ? $_POST['action'] : ""; if($action == "update") { $query = "update employee INNER JOIN department ON employee.department=de

此代码是一个字段问题。文件的格式为int,而值的格式为varchar。那么如何更改联接查询

  <?php 
include 'dblayer.php';
$action = isset( $_POST['action'] ) ? $_POST['action'] : "";
if($action == "update")
{ 
    $query = "update employee
    INNER JOIN department ON employee.department=department.dept_id SET
    fname = '".$mysqli->real_escape_string($_POST['fname'])."',
    lname  = '".$mysqli->real_escape_string($_POST['lname'])."',
    dept  = '".$mysqli->real_escape_string($_POST['department'])."',
    where id='".$mysqli->real_escape_string($_REQUEST['id'])."'";
    if( $mysqli->query($query) )
     {
        echo "<script>alert('employee Data updated successfully!')</script>";
        echo "<script>window.open('view.php')</script>";
    }
    else
    {
        echo "Database Error: Unable to update record.";
    }
    }
    $query = "SELECT  employee.id, employee.fname, employee.lname,    department.department from employee INNER JOIN department  ON  employee.department = department.dept_id where employee.id='".$mysqli-    >real_escape_string($_REQUEST['id'])."' limit 0,1";
    $result = $mysqli->query($query );
    $row = $result->fetch_assoc();
    $fname = $row['fname'];
    $lname = $row['lname'];
    $dept = $row['department'];
   ?>

我不会百分之百地反驳你的问题,但我会尽力帮助你

首先,tabel的id是主的和自动递增的,所以更新此行没有意义

其次,要比较内部联接中的这两行,它们的数据库行必须具有相同的INT属性

employee.department=department.dept_id
此行中的employee.department是department.dept\u ID中的ID吗

第三,将代码更改为

 where employee.id

我不会百分之百地反驳你的问题,但我会尽力帮助你

首先,tabel的id是主的和自动递增的,所以更新此行没有意义

其次,要比较内部联接中的这两行,它们的数据库行必须具有相同的INT属性

employee.department=department.dept_id
此行中的employee.department是department.dept\u ID中的ID吗

第三,将代码更改为

 where employee.id

部门字段仅不起作用请尝试用更易懂的英语解释您的问题。这样的话,我看不懂。是否将VARCHAR传递给只接受INT的db字段?更新查询不起作用。因为dept在int中归档,但值在varchar中。所以,我如何传递值并进入存储数据库
你说的是部门字段主键
,在你的查询中,你试图更新它,这是永远不会发生的部门字段仅不工作请尝试用更易懂的英语解释你的问题。这样的话,我看不懂。是否将VARCHAR传递给只接受INT的db字段?更新查询不起作用。因为dept在int中归档,但值在varchar中。所以,我如何传递值并进入存储数据库
您说的部门字段主键
,并且在您的查询中尝试更新它,这是永远不会发生的partment是外键。Department是外键。