Click here to Skip to main content
15,888,297 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi I am new, Pls help me the following issue. When click the update button, ID should be to another page to process the update function. Below is my entire code

index.php

PHP
<?php
include_once '../../inc/config.inc.php';

$sql="SELECT * FROM demo  order by id";
    try {
            $result = mysqli_query($con,$sql);  
            include 'view.html.php'; 
         } 
    catch (PDOException $e) 
        {
           echo $e->getMessage() . "\n";
           file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
//           $output = 'Error fetching authors from database!';
//           include '../../notification/errormsg.php';
           exit();
        }


view.html.php

PHP
<Script Language="javascript">
function change_action()
    {
        var frm_obj=document.getElementById("frm");
        frm_obj.action="data.php";
    }
</Script>

<h3>User Details</h3>
<form action="" method="POST" id="frm" >
    <table width="100%" align="center" cellpadding="4" cellspacing="1">
        <tr>
            
            <td>ID</td>
            <td>ID</td>
            <td>NAME</td>
            <td>FIRST NAME</td>
            <td>AGE</td>
            <td></td>
            
        </tr>
        <?php
            if(isset($result)){
            while($row = mysqli_fetch_array($result)){ ?>
             <tr>
                
                <td><input type="text" name="vid" value="<?php echo $row['id'];?>"/></td>
                <td><?php echo $row['id'];?></td>
                <td><?php echo $row['name'];?></td>
                <td><?php echo $row['firstname'];?></td>
                <td><?php echo $row['age'] ;?></td>
                <td><input type="submit" value="update" name="update" onclick="change_action()">
                <input type="submit" value="delete" name="delete" onclick="change_action()">
                </td>                
              </tr>  
         <?php
            } 
         
            }
            mysqli_close($con);
        ?>
   
    </table>
</FORM>
<?php
include '../../inc/footer.php';


data.php

PHP
<?php
include_once '../../inc/config.inc.php';
if (isset($_POST['update']) && $_POST['update']  != "" )
        {
            $id = $_POST['vid'];
            $sql="SELECT * FROM demo where id='$id'";
            $result = mysqli_query($con,$sql);
            include 'edit.php';
     }


edit.php
PHP
<?php
echo 'edit.php';
  
if(isset($result))
    {
        while($row = mysqli_fetch_array($result))
                { 
                    echo $row['id'];'<br>';
                    echo $row['name'];'<br>';
                    echo $row['firstname'];'<br>';
                    echo $row['age'];'<br>';
    
                }
    }


thank you

maideen
Posted
Updated 30-May-22 7:37am
Comments
Mohibur Rashid 3-Apr-14 1:44am    
look up action

You can solve your problem by using Jquery

Give id to each element which holds id like

HTML
<table>
   <tr id="r1">
      <td id="idn1">1</td>
      <td>Hoffman</td>
      <td>Tatyana</td>
      <td>100</td>
      <td onclick="update('idn1',1)">Update</td>
   </tr>

   <tr id="r1">
      <td id="idn2">2</td>
      <td>Atkins</td>
      <td>Ishmael</td>
      <td>44</td>
      <td onclick="update('idn2',2)">Update</td>
   </tr>
   ...
   ...
   ...
   ...
   ...
</table>

Now write the javascript function
JavaScript
function update(idn,n)
{
  cid=$('#'+idn).val();
  $.post("your_next.php?idn="+cid,function(data){
    $("r"+n).html(data);
  });
}


In "your_next.php" you have the id to whom you want to update values.....
 
Share this answer
 
<a href="data.php?id=1">Update</a>


on data.php

$myId = $_GET['id'];
 
Share this answer
 
v2
I am telling the scnario. I have page with all customer data as grid format. last column is "UPDATE". If I select 5th row and click update, next page open the details of 5th row customer data.
My sql command:

$sql="select id,name,firstname,age from customer where id='$id'"

How can i pass the id for select customer to the next page to retrive data from mysql database and to update if any changes.

Pls help me
HTML
ID  NAME          FIRST NAME    AGE
1   Hoffman       Tatyana       100     Update
2   Atkins        Ishmael        44     Update
3   Hamilton      Mohammad       73     Update
4   Murray        Troy       18     Update
5   Schwartz      Carla      79     Update
6   Bond          Leno       33     Update
7   Noble         Georgia        88     Update
8   Frederick     Bradley        80     Update
9   Chambers      Aphrodite      63     Update
10  Schultz       Allegra        90     Update
11  Garrett       Lillith        20     Update
12  Mcdaniel      Venus      89     Update
13  Acevedo       Iola       26     Update
 
Share this answer
 
you can just put link lines as below:


Update

on data.php

$myId = $_GET['id'];

or use

@$_GET['id'];
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900