简体   繁体   中英

php form: cannot update the database, query with multiple join

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM