Create a PHP script to insert, retrieve, update, and delete records from a MySQL table.
Source Code:
<?php
$connection=mysqli_connect("localhost","root","","phpdb"); $query="create table student(sid int,sname varchar(30).marks float)"; if(mysqli_query($connection, $query)) { echo "Table creation Successfull!!";)
else{
echo "Error creating table:" mysqli_error(Sconnection). "<br>";} $query1="insert into student values(101, 'Sreejith',99);"; $queryl.="insert into student values(102, 'Meera', 79);"; Squery1.="insert into student values(103,'Anu',69);"; if(mysqli_multi_query($connection.Squery1)){ echo "Insertion Successfull!!";}
else
echo "Error insertion:"mysqli_error($connection). "<br>";) $query2="update student set marks=100 where sid=101"; $con2=mysqli_query($connection, $query2); if($con2)( echo "Updation Successfull!!";)
else{ echo "Error creating table:" mysqli_error($connection). "<br>";} $query3="delete from student where sid=103"; $con3=mysqli_query($connection, Squery3); if($con3){ echo "Deletion Successfull!!";}
else{ echo "Error creating table:" mysqli_error($connection). "<br>";) $query4 = "SELECT * FROM student"; $con1 = mysqli_query($connection, $query4); if (mysqli_num_rows($con1) > 0) { while ($row = mysqli_fetch_assoc($con1)) { echo "ID:". Srow["sid"]."<br>"; echo "Name:". $row["sname"]."<br>"; echo "Marks: ".$row["marks"]."<br><br>";}} else ( echo "Error retrieving data:" mysqli_error($connection). "<br>"; }
?>
Comments