php表单:无法更新数据库,用多个连接进行查询 [英] php form: cannot update the database, query with multiple join

查看:220
本文介绍了php表单:无法更新数据库,用多个连接进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑#2: SQLfiddle



编辑#1:我现在看到了所有的字段,但无法更新。所有查询本身都有效。



我有一个页面,必须显示来自数据库的信息以进行更新。该查询具有多个连接。查询本身是有效的。



我没有收到错误消息(并且为了获得隐藏或禁用错误消息的常用方法不起作用),所以我不知道什么是错的,但是表单是空白的,不会编辑任何东西(有时空白表单将信息编辑为空字段)。

我多次遇到类似的问题(并不断地谷歌的一切)和错误不同,但我不得不处理以前的事情似乎是原因。



这是代码:

 <?php 
header('Content-type:text / html; charset = utf-8');

包含../config.php;

isset($ _ GET ['idorg'])? $ idorg = $ _ GET ['idorg']:$ idorg ='';
isset($ _ GET ['nameorg'])? $ nameorg = $ _ GET ['nameorg']:$ nameorg ='';
isset($ _ GET ['typeorg'])? $ typeorg = $ _ GET ['typeorg']:$ typeorg ='';
isset($ _ GET ['emailorg'])? $ emailorg = $ _ GET ['emailorg']:$ emailorg ='';
isset($ _ GET ['cperorg'])? $ cperorg = $ _ GET ['cperorg']:$ cperorg ='';
isset($ _ GET ['conorg'])? $ conorg = $ _ GET ['conorg']:$ conorg ='';
isset($ _ GET ['comorg'])? $ comorg = $ _ GET ['comorg']:$ comorg ='';
isset($ _ GET ['idci'])? $ idci = $ _ GET ['idci']:$ idci ='';
isset($ _ GET ['nameci'])? $ nameci = $ _ GET ['nameci']:$ nameci ='';
isset($ _ GET ['nameco'])? $ nameco = $ _ GET ['nameco']:$ nameco ='';
isset($ _ GET ['idco'])? $ idco = $ _ GET ['idco']:$ idco ='';
isset($ _ GET ['submit'])? $ submit = true:$ submit = false;


if(!$ submit)
{

$ query =select dISTINCT org.idorg,org.nameorg,org.typeorg,org .emailorg,org.cperorg,org.conorg,org.comorg,idci,country.nameco,city.nameci,idco
from org
加入city.idci = org.city_idci
JOIN country on country.idco = org.city_country_idco
where idorg =?
group by idorg

;

if($ stmt = $ mysqli-> prepare($ query))
{

$ stmt-> bind_param(我,$ idorg);
$ stmt-> execute();
$ stmt-> bind_result($ idorg,$ nameorg,$ typeorg,$ emailorg,$ cperorg,$ conorg,$ comorg,$ idci,$ nameci,$ nameco,$ idco);
$ stmt-> fetch();

$ stmt-> close();
$ mysqli-> close();

echo'
<!DOCTYPE html>
< html>
< head>
< style> h1 {color:red;} label {color:darkred;}< / style>
< title>编辑使用者< / title>
< meta charset =UTF-8>
< / head>
< body>
< h1>编辑机构:< / h1>
< form action =method =GET>
< label> ID< / label>< input readonly name =idorgvalue ='。$ idorg。'>< br>
< label> Name org< / label>< input type =textname =nameorgvalue ='。$ nameorg。'>< br>
< label>类型< / label>< input type =textname =typeorgvalue ='。$ typeorg。'>< br>
< label>电子邮件< / label>< input type =textname =emailorgvalue ='。$ emailorg。'>< br>
< label>联系人< / label>< input type =textname =cperorgvalue ='。$ cperorg。'>< br>
< label> contact< / label>< input type =textname =conorgvalue ='。$ conorg。'>< br>
< label>评论< / label><输入类型=文字name =comorgvalue ='。comorg。'>< br>
< label> cityID< / label>< input readonly name =idcivalue ='。$ idci。'>< br>
< label>城市< / label><输入类型=textname =namecivalue ='。$ nameci。'>< br>
< label> country< / label>< input type =textname =namecovalue ='。$ nameco。'>< br>
< label> countryID< / label>< input readonly name =idcivalue ='。$ idco。'>< br>
< input type =resetvalue =clear>
< input type =submitvalue =addname =submit>< br>
< / form>
< / body>

< / html>
';
}
} else {
$ query1 =UPDATE org
加入city.idci = org.city_idci
加入country.idco = org.city_country_idco
SET nameorg =?,typeorg =?,nameco = ?, nameci =?emailorg = ?, cperorg = ?, conorg =?,comorg = ?, idci =?,idco =?WHERE idorg =?;

if($ stmt = $ mysqli-> prepare($ query1))
{

$ stmt-> bind_param('ssssssssiii',$ nameorg ,$ typeorg,$ nameco,$ nameci,$ emailorg,$ cperorg,$ conorg,$ comorg,$ idci,$ idco,$ idorg);

$ stmt-> execute();
$ stmt-> close();
}
$ mysqli-> close();
header('Location:view.php');
// echo< a href ='view.php'> back< / a>;
}

?>

这是 EER Diagram 的数据库。



预先感谢您:)

解决方案

为什么您使用

if(!$ submit)???



可能是

if($ submit)


EDIT#2: SQLfiddle

EDIT#1: i see everything in fields now, but cannot update. all queries by themselves work.

I have a page that must show information from database for update. The query has multiple join. The query itself works.

I do not get error message(and the usual methods in order to get a hidden or disabled error message do not work), so I do not know what is wrong, but the form is blank and doesn't edit anything(sometimes blank forms edit information to empty fields).

I've had similar issues many times (and constantly google everything) and errors differ, but none of the previous things I had to deal with seem to be the reason.

Here is the code:

<?php 
header('Content-type: text/html; charset=utf-8');

include "../config.php";

isset($_GET['idorg']) ? $idorg=$_GET['idorg'] : $idorg='';
isset($_GET['nameorg']) ? $nameorg=$_GET['nameorg'] : $nameorg='';
isset($_GET['typeorg']) ? $typeorg=$_GET['typeorg'] : $typeorg='';
isset($_GET['emailorg']) ? $emailorg=$_GET['emailorg'] : $emailorg='';
isset($_GET['cperorg']) ? $cperorg=$_GET['cperorg'] : $cperorg='';
isset($_GET['conorg']) ? $conorg=$_GET['conorg'] : $conorg='';
isset($_GET['comorg']) ? $comorg=$_GET['comorg'] : $comorg='';
isset($_GET['idci']) ? $idci=$_GET['idci'] : $idci='';
isset($_GET['nameci']) ? $nameci=$_GET['nameci'] : $nameci='';
isset($_GET['nameco']) ? $nameco=$_GET['nameco'] : $nameco='';
isset($_GET['idco']) ? $idco=$_GET['idco'] : $idco='';
isset($_GET['submit']) ? $submit=true : $submit=false;


if(!$submit)
{

$query = "select dISTINCT   org.idorg, org.nameorg, org.typeorg, org.emailorg,  org.cperorg, org.conorg, org.comorg, idci, country.nameco, city.nameci, idco
from org 
join city on city.idci=org.city_idci 
JOIN country on country.idco=org.city_country_idco
where idorg=?
group by idorg

";

if($stmt = $mysqli->prepare($query))
{

$stmt-> bind_param("i", $idorg);
$stmt->execute();
$stmt->bind_result($idorg, $nameorg, $typeorg, $emailorg, $cperorg, $conorg, $comorg, $idci,$nameci,  $nameco, $idco);
$stmt->fetch();

$stmt->close();
$mysqli->close();

    echo'
    <!DOCTYPE html>
<html>
<head>
<style>h1{color:red;}label{color:darkred;}</style>
<title>Edit user</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Edit organisation:</h1>
<form action="" method="GET">
<label>ID </label><input readonly name="idorg" value="'.$idorg.'"><br>
<label>Name org </label><input type="text" name="nameorg" value="'.$nameorg.'"><br>
<label>Type </label><input type="text" name="typeorg" value="'.$typeorg.'"><br>
<label>e-mail </label><input type="text" name="emailorg" value="'.$emailorg.'"><br>
<label>contact person </label><input type="text" name="cperorg" value="'.$cperorg.'"><br>
<label>contact</label><input type="text" name="conorg" value="'.$conorg.'"><br>
<label>comment </label><input type="text" name="comorg" value="'.$comorg.'"><br>
<label>cityID </label><input readonly name="idci" value="'.$idci.'"><br>
<label>city </label><input type="text" name="nameci" value="'.$nameci.'"><br>
<label>country </label><input type="text" name="nameco" value="'.$nameco.'"><br>
<label>countryID </label><input readonly name="idci" value="'.$idco.'"><br>
<input type="reset" value="clear">
<input type="submit" value="add" name="submit"><br>
</form>
</body>

</html>
';
}
}else{
$query1 = "UPDATE org
join city on city.idci=org.city_idci 
JOIN country on country.idco=org.city_country_idco
SET nameorg=?, typeorg=?, nameco=?, nameci=? emailorg=?, cperorg=?, conorg=?, comorg=?, idci=?, idco=?  WHERE idorg=?";

if($stmt = $mysqli->prepare($query1))
{

$stmt->bind_param('ssssssssiii', $nameorg, $typeorg,$nameco, $nameci,  $emailorg, $cperorg, $conorg, $comorg, $idci, $idco, $idorg);

$stmt->execute();
$stmt->close();
}
$mysqli->close();
header('Location: view.php');
//echo "<a href='view.php'>back</a>";
}

?>

Here is EER Diagram of database.

Thank you in advance :)

解决方案

why you use
if(!$submit) ???

may be it'll be
if($submit)

这篇关于php表单:无法更新数据库,用多个连接进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆