ale Posted June 20, 2015 Share Posted June 20, 2015 (edited) Hi When I am doing the table update I do not see that one article is updated called naziv_artikla. Well, the article is updated in the database when I open my phpmyAdmin, but when I am showing it on the screen, selecting all the articles from the database I do not see the update of naziv_artikla. Is there problem with the hidden field? I removed it from the code, but then is displayed some error (code is not working properly). Can anybody tells me what should I fix??? Thanks This is my code for selecting data from the database. <?php $con=mysqli_connect("localhost","root","aco123","sifrarnik"); // Provjeri konekciju if (mysqli_connect_errno()) { echo "Failed to connect to MySQLi: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM artikli ORDER BY id_artikla ASC"); echo "<table border='1'> <tr> <th>Id artikla</th> <th>Naziv artikla</th> <th>Cijena artikla</th> <th>Na stanju</th> <th>Ukupno u KM</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<form action = update1.php method = post>"; echo "<tr>"; echo "<td>" . $row['id_artikla'] . " </td>"; echo "<td>" ."<input type = text name = naziv_artikla value = ". $row['naziv_artikla'] . " </td>"; echo "<td>" ."<input type = text name = cijena_artikla value = ". $row['cijena_artikla'] . " </td>"; echo "<td>" ."<input type = text name = na_stanju value = ". $row['na_stanju'] . " </td>"; echo "<td>" . $row ['cijena_artikla'] * $row ['na_stanju'] . " </td>"; echo "<td>" ."<input type = hidden name = hidden value = ". $row['id_artikla'] . " </td>"; echo "<td>" ."<input type = submit name = update value = Update>"; echo "</tr>"; echo "</form>"; } $ukupno_u_km = $row ['cijena_artikla'] * $row ['na_stanju']; mysqli_close($con); ?> And this is my update code. <?php $servername = "localhost"; $username = "root"; $password = "aco123"; $dbname = "sifrarnik"; // Kreiranje konekcije $conn = mysqli_connect($servername, $username, $password, $dbname); // Provjera konekcije if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // Sql upit za update podataka $sql = "UPDATE artikli SET naziv_artikla = '$_POST[naziv_artikla]', cijena_artikla = '$_POST[cijena_artikla]', na_stanju = '$_POST[na_stanju]' WHERE naziv_artikla = '$_POST[hidden]'"; mysqli_query ($conn, $sql); // Provjera upita if (mysqli_query($conn, $sql)) { echo header ("Location: tabela_sa_podacima1.php"); } else { echo "Error updating record: " . mysqli_error($conn); } mysqli_close($conn); ?> Edited June 20, 2015 by ale Link to comment Share on other sites More sharing options...
dauruk0512 Posted June 20, 2015 Share Posted June 20, 2015 What errors shown ? 1 Link to comment Share on other sites More sharing options...
Alatoru Posted June 22, 2015 Share Posted June 22, 2015 Maybe you need associative array for that. Like this: mysqli_fetch_assoc($result) . Try that. 1 Link to comment Share on other sites More sharing options...
ale Posted June 22, 2015 Author Share Posted June 22, 2015 (edited) I will try it.. Edited June 22, 2015 by ale Link to comment Share on other sites More sharing options...
dsonesuk Posted June 22, 2015 Share Posted June 22, 2015 (edited) shouldn't this WHERE naziv_artikla = '$_POST[hidden]'"; be WHERE id_artikla = '$_POST[hidden]'"; I take this as being a id ref being placed in hidden input, so i would assume it should reference the same when updating. You won't get any error message cause there is no matching record of title against id, so it is not a error, the record does not exist. Edited June 22, 2015 by dsonesuk 1 Link to comment Share on other sites More sharing options...
ale Posted June 22, 2015 Author Share Posted June 22, 2015 (edited) I already tried that but there is still some mistake... It is not working... Edited June 22, 2015 by ale Link to comment Share on other sites More sharing options...
Alatoru Posted June 22, 2015 Share Posted June 22, 2015 I just noticed that in second php code, you are missing almost everywhere ' for $_POST[something] . You left it without quotes. Maybe that can cause the problem. Link to comment Share on other sites More sharing options...
ale Posted June 22, 2015 Author Share Posted June 22, 2015 Oh I have a quotes... That is not a problem Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now