Showing posts with label update query in mysql. Show all posts
Showing posts with label update query in mysql. Show all posts

Tuesday, 20 September 2016

HOW TO CREAT UPTATE USING MYSQL IN PHP


HOW TO CREAT UPTATE USING MYSQL IN PHP
        using MYSQL creat and update database in php 


<?php 
//database connection
mysql_connect("localhost","root","");
//database selection
mysql_select_db("exam");

$q = "select * from result";
$rs  =  mysql_query($q);
$num = mysql_num_rows($rs);

//$row =  mysql_fetch_array($rs);



?>

<body>

    <table border="1" cellspacing="1">
    <tr>
        <td>Name</td>
            <td>Password</td>
         
        </tr>
        <?php if ($num > 0){ while($row = mysql_fetch_array($rs)){?>
   
        <tr>
            <td><?php echo $row['Name'];?></td>
           <td><a href="update.php?upt=<?php echo $row['id']; ?>">update</a></td>
        </tr>
            <?php }}?>
        
    </table>



<form method="post">
<table border="1" cellspacing="1">
   
<?php 
if(isset($_REQUEST['upt'])){
if(isset($_POST['btn'])){
$Name = $_POST['Name'];
$id = $_REQUEST['upt'];
$q  = "update result set Name='$Name' where id ='$id'";
$rs = mysql_query($q);
}

$id = $_REQUEST['upt'];
$sel = "select * from result where id = '$id'";
$rs1 = mysql_query($sel);

while($row = mysql_fetch_array($rs1)){?>
   <tr>
        <td>Name</td>         
        </tr>
        
        <tr>
            <td><input type="text" value="<?php echo $row['Name'];?>" name="Name" /></td>
            <td><input type="submit" name="btn" value="click here"/></td>
        </tr>
        <?php }} ?>
            </table>
    

</form>
</body>