Rayyan
Rayyan

Reputation: 1

how to update the data from primary key field?

i got problem when update idSoal (PK),but for other can do it,the sql code is like this:

==>index.php

<td align="center"><a href="editSoal.php?idSoal=<?php echo $row['idSoal']; ?>"><img src="images/edit.png" /></a></td>

==>editSoal.php

$id_soal=$_GET['idSoal'];
$sql = "SELECT * FROM soal  WHERE idSoal = '$id_soal'"; 
.............
<form id="contactform" action="proses_editSoal.php" method="POST"> 
    <label for="id_soal">ID SOAL</label>
      <input id="id_soal" name="id_soal" value="<?php echo $row['idSoal']; ?>" required="" type="text" "> 
    <label for="soal">SOAL</label>  
     <input id="nama" name="soal" value="<?php echo $row['soal']; ?>" required=""  type="text" > 
    <input class="buttom" name="submit" id="submit" tabindex="5" value="Edit!" type="submit">    
</form> 

==>proses_editSoal.php

$id_soal=$_POST['id_soal'];
$soal = $_POST['soal'];
$query="UPDATE soal SET idSoal='$id_soal',soal='$soal' WHERE idSoal='$id_soal'";

for "soal" i can update it. where is my problem?

Upvotes: 0

Views: 61

Answers (1)

Tornike
Tornike

Reputation: 1254

It seems you are using same variable in SET and WHERE for idSoal value. So you are not changing the value of it.

In mysql you can update any field. Try to print the query and you'll see the problem.

Upvotes: 1

Related Questions