So I am a highschooler and I have this subject something like an intro to programming.
And the other day we got an assignment to create a page which will send data from a form that is located on the page to MySQL database table and then read that sent data and write it on the page. It is something like a chat, you send your message and username and those get send to the database table and then written on the original page. Now my problem is that my database table will not accept any data which I type in the form. I mean I dont know is it the code or my database and my table in MySQL.
The programm did work until I deleted/dropped a few rows from my table, could that be the problem ? The variables and all the names are in my native language.
Could someone help my find the problem and a solution, please ?
Here is the code:
<body>
<?php
error_reporting(0);
$server= 'localhost';
$korisnik='mojkorisnik';
$pass='mojalozinka';
$baza='mojabaza';
$conn= mysqli_connect($server, $korisnik, $pass, $baza);
if(!$conn){
die("Connection failed:".mysql_error());
}
$por=$_POST["poruka"];
$im=$_POST["ime"];
$rezultat= mysqli_query($conn,"SELECT*FROM mojeporuke");
$brojredova=mysqli_num_rows($rezultat);
?>
<div id="okolo">
<div id="zaglavlje"><img src="slike/logo.jpg" width="257" height="100" alt="logo" />
</div>
<div id="sadrzaj">
<p>Dobro došli u našu knjigu gostiju!<br />
Možete ostaviti i svoju poruku!</p>
<?php
if($brojredova){
?>
<table width="630" border="0" cellspacing="1" class="tablica">
<tr class="naslovni">
<td width="20">ID</td>
<td width="380">Poruka</td>
<td>Poslao</td>
</tr>
<?php
while ($red=mysqli_fetch_array($rezultat)){
echo"<tr class=\"ostali\"><td>".$red['id']."</td><td>".$red['poruka']."</td><td>".$red['poslao']."</td></tr>"; }
?>
</table>
<?php
}else{
echo'<p>Još nema poruka!</p>';
}
if($im=="" or $por==""){
echo"Greška: Niste ispunili sva polja!";
}else
$upis=mysqli_query($conn,"INSERT INTO mojeporuke (id,poslao,poruka) VALUES ('$brojredova','$im', '$por')");
?>
<form id="form1" name="form1" method="post" action="index.php">
<p>
<label for="poruka">Poruka</label>
<textarea name="poruka" id="poruka" cols="35" rows="3"></textarea>
</p>
<p>
<label for="ime"> Ime</label>
<input name="ime" type="text" id="ime" size="35" />
<input name="bio" type="hidden" id="bio" value="da" />
</p>
<p>
<input type="submit" name="posalji" id="posalji" value=" Pošalji " onsubmit="return checkForm()" />
</p>
</form>
<p> </p>
<p> </p>
</div>
<div id="dole">
©knjiga gostiju za laboratorijske vježbe 4.h i 3.F razreda </div>
</div>
<?php
mysqli_close($conn);
?>
</body>
</html>