Edit and Update database using PHP

<html>
<body>
<?php

$conn=mysql_connect("localhost","root","");
mysql_select_db("test",$conn) or die('Could not connect: ' . mysql_error());

if(isset($_POST['sdbupdate'])){
$id=$_POST['id'];
$name=$_POST['username'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$phno=$_POST['phno'];
$url=$_POST['url'];
$address=$_POST['address'];
$update="UPDATE users SET name='".$name."',email='".$email."',gender='".$gender."',phno='".$phno."',url='".$url."',address='".$address."' WHERE id='".$id."'";
//echo $update;
//exit();
mysql_query($update);
header("location:display.php");
}
?>
<?php
if(isset($_GET['id'])){
$getid=$_GET['id'];
$query="select * from test where id = $getid";
$display=mysql_query($query);
$row=mysql_fetch_assoc($display);
//if($row['gender']=="f"){
//echo "femle";
//}
//echo $row['gender'];
//exit();
?>
<form method="post" action="sdbupdate.php">
<table  width="100%" border="1">
    <tr>
        <td>Username</td>
        <td><input type="text" name="username" value="<?php echo $row['name']; ?>"></td>
    </tr>
    <tr>
        <td>E-Mail</td>
        <td><input type="text" name="email" value="<?php echo $row['email']; ?>"></td>
    </tr>
    <tr>
        <td>gender</td>
        <td><input type="radio" name="gender" value="<?php echo $row['gender']; ?>" <?php if($row['gender']=="f"){ echo "checked";} ?>/>Female
        <input type="radio" name="gender" value="<?php echo $row['gender']; ?>" <?php if($row['gender']=="m") { echo "checked"; }?>/> Male </td>
    </tr>
    <tr>
        <td>Phone Number</td>
        <td><input type="text" name="phno" value="<?php echo $row['phno']; ?>"></td>
    </tr>
    <tr>
        <td>Url</td>
        <td><input type="text" name="url" value="<?php echo $row['url']; ?>"></td>
    </tr>
    <tr>
        <td>Address</td>
        <td><textarea name="address" rows="10" cols="23" ><?php echo $row['address']; ?></textarea></td>
    </tr>
    <tr>
                <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
        <td colspan="2" align="center"><input type="submit" name="sdbupdate" value="update"></td>
    </tr>
</table>
</form>
<?php
}
?>
</body>
</html>

Post a Comment

Analytics