<?php
//Provjerava da li se korisnik vec ulogovao. Ako nije, ispisace gresku.
session_start();
if (!isset($_SESSION['korisnik'])) {
die('Za pristup ovoj stranici morate se prvo ulogovati.');
}
if ($_SESSION['korisnik'] != 'administrator') {
die('Za pristup ovoj stranici morate se prvo ulogovati kao administrator.');
}
//Podaci o bazi podataka
$hostname = ""; $db_username = ""; $db_password = ""; $db_name = "";
$con = mysql_connect($hostname,$db_username,$db_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);
$sql = mysql_query("select * from sections");
$sql_2 = mysql_query("select * from sections");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administracija aplikacije</title>
</head>
<body>
<p align="center"><font color="#000000"><strong>Administracija aplikacije</strong></font></p>
<form id="form1" name="form1" method="post" action="">
<p align="center"><font color="#0000FF"> Registracija korisnika</font></p>
<table width="286" height="199" border="0" align="center">
<tr>
<td width="95">Ime</td>
<td width="181">
<div align="left">
<input type="text" name="ime" id="ime" />
</div></td>
</tr>
<tr>
<td height="31">Prezime</td>
<td><div align="left">
<input type="text" name="prezime" id="prezime" />
</div></td>
</tr>
<tr>
<td>Korisničko ime</td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td>Lozinka</td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td>Smijer</td>
<td><select name="smjer_show" id="smjer_show">
<?php
while($row = mysql_fetch_array($sql))
{
echo "<option>".$row['SectionName']."</option>";
}
?>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="register" id="register" value="- Registruj - " /></td>
</tr>
</table>
<p>
<label></label>
<br>
<?php
if (isset($_POST['register'])){
$ime = $_POST['ime'];
$prezime = $_POST['prezime'];
$username = $_POST['username'];
$password = $_POST['password'];
$smjer_show = $_POST['smjer_show'];
if (empty($ime) || empty($prezime) || empty($username) || empty($password)){
die ("ERROR: Niste unijeli sve potrebne podatke!");
}
$con = mysql_connect($hostname,$db_username,$db_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);
$sql = mysql_query("select id from sections where sectionname ='".$smjer_show."'");
$smjer = mysql_fetch_array($sql);
$sql = "insert into students values (NULL,'".$ime."','".$prezime."','".$username."','".$password."',".$smjer['id'].")";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Podaci uspjesno uneseni u bazu podataka!";
}
?>
<br>
</p>
<hr />
<p align="center"><font color="#0000FF">Šifarnik smijerova</font></p>
<p align="center">Unos novog smijera:
<input type="text" name="smjer_new" id="smjer_new" />
</p>
<p align="center">Sačuvaj smijer:
<input type="submit" name="sacuvaj_smjer" id="sacuvaj_smjer" value="- Sacuvaj smijer -" />
</p>
<p> </p>
<p>
<label></label>
</p>
</p><br>
<?php
if (isset($_POST['unos_predmeta'])){
$enter_predmet = $_POST['enter_predmet'];
$smjer_select = $_POST['smjer_select'];
if (empty($enter_predmet)){
die ("ERROR: Niste unijeli ime predmeta!");
}
$con = mysql_connect($hostname,$db_username,$db_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);
$sql = mysql_query("select id from sections where sectionname ='".$smjer_select."'");
$smjer = mysql_fetch_array($sql);
$sql = "insert into subjects values (NULL,'".$enter_predmet."',".$smjer['id'].")";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Podaci uspjesno uneseni u bazu podataka!";
}
?>
<br>
<hr />
<p align="center"><font color="#0000FF">Šifarnik predmeta</font></p>
<p align="center">Naziv predmeta:
<input type="text" name="enter_predmet" id="enter_predmet" />
</p>
<p align="center">Smijer kojem predmet pripada:
<select name="smjer_select" id="smjer_select">
<?php
while($row = mysql_fetch_array($sql_2))
{
echo "<option>".$row['SectionName']."</option>";
}
?>
</select>
</p>
<p align="center">
<input type="submit" name="unos_predmeta" id="unos_predmeta" value="- Sacuvaj predmet -" />
</p>
<p>
<label></label>
</p>
<?php
if (isset($_POST['sacuvaj_smjer'])){
$smjer_new = $_POST['smjer_new'];
if (empty($smjer_new)){
die ("ERROR: Niste unijeli naziv smjera!");
}
$con = mysql_connect($hostname,$db_username,$db_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);
$sql = "insert into sections values (NULL,'".$smjer_new."')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Podaci uspjesno uneseni u bazu podataka!";
}
?>
</form>
<p align="center"><a href="logout.php">LogOut </a></p>
</body>
</html>
<?php
mysql_close($con);
?>
part with sacuvaj_smjer is giving me this error
Error: Table 'a9752689_1.sections' doesn't exist
and I do have database with sections table and I have working connections, I just deleted it from this post
thanks in advance