I cannot seem to make this code work. It is also a base for my other page(update) that doesn't want to update.
The code is supposed to add information into the database.
The query works by itself. I thought that maybe query is too complex(because pro has fields that are connected to different tables: fundpro, city, typepro and city is connected to country), but since it works by itself I guess there is a way to make it work in PHP and I'm just doing it wrong.
In update page(link above to question and the code) form shows correct fields, so I assume there are no major mistakes in both pages, the problem is in the "delivery" of the information to the database or something.
I really need the insert-data page, it is practically the only page i really need in the end, and I cannot make it work to my org and pro tables, while my country tables has workable add and edit pages that is quite similar.
I ran out of ideas what might be the reason and I do not know how to make it work for me. Maybe someone sees the problem or knows an alternative approach?
tl;dr data doesn't get INSERTed into the database from the fields. query is coccer by itself, based on update.php file, form returns the information correctly.
Here are SQLFiddle and EER Diagram.
<?php
header('Content-type: text/html; charset=utf-8');
isset($_GET['submit'])?$submit=true:$submit=false;
if(!$submit){
?>
<!DOCTYPE html>
<html>
<head>
<style>h1{color:red;}label{color:darkred;}</style>
<title>Add project</title>
<meta charset=”UTF-8”>
</head>
<body>
<h1>Add project:</h1>
<form name="f1" action="" method="GET" onSubmit="return validateForm(this)">
<label>IDpro </label><input type="text" name="idpro"><br>
<label>numpro</label><input type="text" name="numpro" ><br>
<label>namepro </label><input type="text" name="namepro" ><br>
<label>datef </label><input type="text" name="datef" ><br>
<label>datet </label><input type="text" name="datet" ><br>
<label>descr </label><input type="text" name="descr" ><br>
<label>typepro </label><input type="text" name="typepro" ><br>
<label>fundpro </label><input type="text" name="fundpro" ><br>
<label>IDci </label><input type="text" name="idpro" ><br>
<input type="reset" value="clear">
<input type="submit" value="add" name="submit"><br>
</form>
</body>
</html>
<?php
}else{
include "../config.php";
isset($_GET['idpro']) ? $idpro=$_GET['idpro'] : $idpro='';
isset($_GET['numpro']) ? $numpro=$_GET['numpro'] : $numpro='';
isset($_GET['namepro']) ? $namepro=$_GET['namepro'] : $namepro='';
isset($_GET['datef']) ? $datef=$_GET['datef'] : $datef='';
isset($_GET['datet']) ? $datet=$_GET['datet'] : $datet='';
isset($_GET['descr']) ? $descr=$_GET['descr'] : $descr='';
isset($_GET['typepro']) ? $typepro=$_GET['typepro'] : $typepro='';
isset($_GET['fundpro']) ? $fundpro=$_GET['fundpro'] : $fundpro='';
isset($_GET['idci']) ? $idci=$_GET['idci'] : $idci='';
$sql="INSERT INTO pro(idpro, numpro, namepro, datef, datet, descr,typepro_idtypepro, fundpro_idfundpro, city_idci) VALUES (?,?,?,?,?,?,?,?,?)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('ssddsiiii', $numpro, $namepro, $datef, $datet,$descr, $typepro_idtypepro, $fundpro_idfundpro, $city_idci, $idpro);
$stmt->execute();
$stmt->close();
$mysqli->close();
header("Location: view.php");
//}
}
?>
UPDATE: simpler code, same pattern:
header('Content-type: text/html; charset=utf-8');
isset($_GET['submit'])?$submit=true:$submit=false;
if(!$submit){
?>
<!DOCTYPE html>
<html>
<head>
<style>h1{color:red;}label{color:darkred;}</style>
<title>Add city</title>
<meta charset=”UTF-8”>
</head>
<body>
<h1>Add city:</h1>
<form name="f1" action="" method="GET" onSubmit="return validateForm(this)" >
<label>city id </label><input type="text" name="idci"><br>
<label>city </label><input type="text" name="nameci"><br>
<label>country id </label><input type="text" name="country_idco"><br>
<input type="reset" value="clear">
<input type="submit" value="add" name="submit"><br>
</body>
</html>
<?php
}else{
include "../config.php";
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='';
//if(($name!='')&&($nameci!='')&&($nameco!='')){
//echo "$name $nameci $nameco";
$sql="INSERT INTO city(idci, nameci,country_idco) VALUES (?,?,?)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('isi', $idci, $nameci, $country_idco);
$stmt->execute();
$stmt->close();
$mysqli->close();
header("Location: view.php");
//}
}