hiiiPipe hiiiPipe - 9 months ago 18
HTML Question

I wanna delete rows form datebase, my code was working and deleting rows then just stop, i do not change anything in code?

So my code was work perfectly, i was able to remove row. After I update datebase with new data, I wanna delete them to test code again and I was enable to delete.
I dont know if is problem in xampp, cuz my code work. Don't know what to try to make work again.

this is my delete.php file:

//connecting to base
// include "spoj.php";
$conn = mysqli_connect('localhost', 'root', '', 'kolegij') or die('Connection error!');
//Defining rows
$id = $_GET['id'];
$query = "DELETE FROM kolegij WHERE id = '$id'";

//delete rows
mysqli_query ($conn, $query);

if (mysqli_affected_rows($conn)==1) {
//if rows delete

<strong>Kolegij je izbrisan</strong><br /><br />

} else {
//rows not deleted

<strong>Niste uspjeli izbrisati kolegij</strong><br /><br />


this is my html code:

<title>Evidencija Kolegija</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<h1>Evidencija Kolegija</h1>
<a href="kolegiji.php">Dodaj novi kolegij</a>
//connect to datebase
// include "spoj.php";
$conn = mysqli_connect('localhost', 'root', '', 'kolegij') or die('Connection error!');
//ispis svih studenata u bazi sortiranih po id-u
$sql_upit="SELECT * FROM kolegij ORDER BY id ASC";
if (!$q=mysqli_query($conn, $sql_upit))
echo "Nismo uspjeli u čitati kolegije iz baze"."<br>". mysqli_query($conn, $sql_upit);
//if rows is === 0 then there is no datea in datebase
if (mysqli_num_rows($q)==0)
echo "Nema kolegija u bazi.";
else {
echo '<table width="1000" border="1px" cellpadding="2" cellspacing="2">';
echo '<tr><td><b>Id</b></td>';
echo '<td><b>Predmeti</b></td>';
echo '<td><b>Profesor</b></td>';
echo '<td><b>Status</b></td>';
//sve dok ima kolegija u bazi
while ($redak=mysqli_fetch_array($q))
echo '<tr><td>'.$redak["id"].'</td>';
echo '<td>'.$redak["Predmeti"].'</td>';
echo '<td>'.$redak["Profesor"].'</td>';
echo '<td>'.$redak["Status"].'</td>';
echo '<td><a href="izmjeni.php?id='.$redak["id"].' ">Uredi kolegij</a></td>';

//delete button
echo 'Obriši
echo '';


I did not change anything in the code I think you did!

This is wrong , and in this form would never have worked

echo '<td><button><a href="brisanje.php?id=$id'.$redak["id"].' ">Obriši</a></button></td>

And should be

echo '<td><button><a href="brisanje.php?id='.$redak["id"].' ">Obriši</a></button></td>