0% found this document useful (0 votes)
3 views

mysql_update&delete

The document contains PHP code for updating and deleting student records in a MySQL database. It includes HTML forms for user input, where users can enter a student ID and name to update or just an ID to delete a record. The code handles database connections, executes SQL queries, and provides feedback on the success or failure of the operations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

mysql_update&delete

The document contains PHP code for updating and deleting student records in a MySQL database. It includes HTML forms for user input, where users can enter a student ID and name to update or just an ID to delete a record. The code handles database connections, executes SQL queries, and provides feedback on the success or failure of the operations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Updating data

<html>

<form method="POST">

id: <input type="text" name="id"><br>

name:<input type="text" name="n1"><br>

<input type="submit" name="s" value="update"><br>

view student details<a href="dis.php">click here</a>

</form>

<?php

$conn=mysqli_connect('localhost','root','','student');

if($conn->connect_error)

die("connection failed".$conn->connect_error);

echo "connection successful";

if(isset($_POST['s']))

$id=$_POST['id'];

$n=$_POST['n1'];

$sql="update stud_details set s_name='$n' where s_id='$id'";

if(mysqli_query($conn,$sql)){

echo "updated successfully";

else

echo "error";
}

?> <html>

<form method="POST">

id: <input type="text" name="id"><br>

name:<input type="text" name="n1"><br>

<input type="submit" name="s" value="update"><br>

view student details<a href="dis.php">click here</a>

</form>

<?php

$conn=mysqli_connect('localhost','root','','student');

if($conn->connect_error)

die("connection failed".$conn->connect_error);

echo "connection successful";

if(isset($_POST['s']))

$id=$_POST['id'];

$n=$_POST['n1'];

$sql="update stud_details set s_name='$n' where s_id='$id'";

if(mysqli_query($conn,$sql)){

echo "updated successfully";

else

echo "error";
}

?>

Deleting data
<html>

<form method="POST">

id: <input type="text" name="id"><br>

<input type="submit" name="s" value="delete"><br>

</form>

<?php

$conn=mysqli_connect('localhost','root','','student');

if($conn->connect_error)

die("connection failed".$conn->connect_error);

echo "connection successful";

if(isset($_POST['s']))

$id=$_POST['id'];

$sql="delete from stud_details where s_id='$id'";

if(mysqli_query($conn,$sql)){

echo "deleted successfully";

else

echo "error".$connect_error;

<html>
<form method="POST">

id: <input type="text" name="id"><br>

<input type="submit" name="s" value="delete"><br>

</form>

<?php

$conn=mysqli_connect('localhost','root','','student');

if($conn->connect_error)

die("connection failed".$conn->connect_error);

echo "connection successful";

if(isset($_POST['s']))

$id=$_POST['id'];

$sql="delete from stud_details where s_id='$id'";

if(mysqli_query($conn,$sql)){

echo "deleted successfully";

else

echo "error".$connect_error;

You might also like