Cant seem to EDIT/MODIFY my php table by id

前端 未结 2 1473
误落风尘
误落风尘 2021-01-27 22:10


        
相关标签:
2条回答
  • 2021-01-27 22:13

    Your code appears a bit confused.

    First of all, why to put the modify routine after output the form? Especially since after modify you send the header function, that fails if previously there are some output.

    Note also a typo: you forgot to properly open the php tag in the form declaration. Change-it in this way:

     <form action="<?php echo $_SERVER['PHP_SELF'];?>" id="form2" method="post" name="form2">
    

    The main problem is that you check if the $_POST[submit] if set, but this is not set, due to the absence of attribute name.

    Change it in this way:

     <input type="submit" name="submit" onclick="clicked(event)" />
    

    Now your script should work (I don't have tested the sql).

    Please also note that your UPDATE routine is redundant: you can reduce the 4 statement to only one in this way:

     $result = mysql_query
     (
        "UPDATE pleasework SET Name='{$_POST[New]}', Cause='{$_POST[New1]}', Symptom='{$_POST[New2]}', Gene_affected='{$_POST[New3]}' WHERE ID={$_POST[id]}"
     );
    

    About PHP Original MySQL API:

    This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0

    0 讨论(0)
  • 2021-01-27 22:34

    NOTE: mysql_* deprecated, so try to use PDO or mysqli_*.

    Simple way:

    <?php
    if(isset($_POST['submit'])){
         $result = mysql_query("UPDATE pleasework 
                                SET Name='".$_POST['New']."',
                                    Cause='".$_POST['New1']."',
                                    Symptom='".$_POST['New2']."',
                                    Gene_affected='".$_POST['New3']."' 
                                WHERE ID=".$_POST['id'].");
    
         if($result ){ 
            echo "Change Successful<br>" ;
            header("Location: databse.php");
         }
         mysql_close($con);
    } 
    

    YOUR PHP:

         while($row = mysql_fetch_array($result))
     {      $spaces = "&nbsp;&nbsp;&nbsp;&nbsp;";
                echo "<TR>";
            echo "<TD>" . $row['ID'] ."</TD>";
            echo "<TD>" . $row['Name'] . $spaces."</TD>";
            echo "<TD>" . $row['Cause'] . $spaces."</TD>";
            echo "<TD>" . $row['Symptom']. $spaces."</TD>"; 
            echo "<TD>" . $row['Gene_affected'] . $spaces."</TD>";     
            echo "<TD><a href='delete.php?id=".$row['ID'] ."'>";
            echo "<font  color='red'>Delete row</font></a>".$spaces."</TD>";
    
            echo "<TD><a href='edit.php?id=" . $row['ID'] ."'>";
            echo "<font color='red'>modify</font></a>".$spaces."</TD>";
          echo "</TR>";
      }
    
    0 讨论(0)
提交回复
热议问题