Add data to Mysql

Loading


<?php
$conn =new mysqli("localhost", "root", "" , "suman");
if (isset($_POST["submit"])) {
$sql = $conn->prepare("INSERT INTO student (name,email) VALUES (?, ?)");
$name = $_POST["name"];
$email= $_POST["email"];
$sql->bind_param("ss", $name, $email);
if($sql->execute()) {
$msg_succ = "Record Added Successfully";
} else {
$msg_error = "Problem in Adding New Record";
}
$sql->close();
$conn->close();
}
?>
<html>
<head>
<title>Add New Student</title>

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22https%3A%2F%2Fcode.jquery.com%2Fjquery-3.6.0.min.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<?php if(!empty($msg_succ)) { ?>
<div class="alert alert-success" role="alert"><?php echo $msg_succ; ?></div>
<?php } if(!empty($msg_error)) { ?>
<div class="alert alert-danger" role="alert"><?php echo $msg_error; ?></div>
<?php } ?>
<div class="container">
<div class="row" >
<div class="col-sm-6">
<form name="frmUser" method="post" action="">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email">
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>



</body>
</html>


0 0 votes
Article Rating
Subscribe
Notify of

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x