Monday, May 6, 2013

PHP MySQL Update Using Forms

<DOCTYPE html>
<html>
<head>
</head>
<body>

<?php
$con=mysqli_connect("localhost","abc","abc456","mydb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

    $newname = mysql_real_escape_string( $_POST["fname"] );

if (isset($_POST['submit'])) {

mysqli_query($con,"UPDATE users SET firstname = '$newname'
WHERE id=3");

header('Location: index.php');
}

mysqli_close($con);

?>

    <form name="profedit" action="" method="post">
    <br>First Name :<input readonly type="text" class="input" name="fname" border="3px" value=" <?php echo"$display"; ?> ">
<br>
<input type="button" id="btnsubmit" value="edit">
<input type="submit" value="Submit" name="submit" id="save" />
<br>
</form>
</body>
</html>

0 Comments:

Post a Comment