Connecting to MySQL from Php and Inserting Records

To connect to MySQL ..

The php running page in Chrome.

 

 


<?php $rollno=""; $physics=""; $chemestry=""; $math=""; &nbsp; $check= isset($_REQUEST['check']); if($check) { $rollno=$_REQUEST['roll']; $physics=$_REQUEST['phy']; $chemestry=$_REQUEST['che']; $math=$_REQUEST['math']; $query="insert into result values ('$rollno','$physics','$chemestry','$math')"; $link= mysqli_connect("localhost", "root", "", "resultdb"); $result= mysqli_query($link, $query); if($result==1) echo 'Inserted'; else echo 'Not Inserted'; &nbsp; } &nbsp; ?>
<!DOCTYPE html>
<!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. -->
<html>
<head>
<title>welcome to mysql</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0A.mn%0A%7B%0Aposition%3A%20absolute%3B%0Awidth%3A%20400px%3B%0Aheight%3A%20300px%3B%0Atop%3A%2010%25%3B%0Aleft%3A%2030%25%3B%0Abackground-color%3A%20moccasin%3B%0A%0A%7D%0A.man%7B%0Aposition%3A%20absolute%3B%0Awidth%3A%2050px%3B%0Aheight%3A%2025px%3B%0Aleft%3A%2015%25%3B%0Abackground-color%3A%20blue%3B%0A%7D%0A%0A%0A%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;style&gt;" title="&lt;style&gt;" />

</head>
<body>

<form method="post" >
<input type="hidden" name="check"/>

<div class="mn"> RollNo<input type="text" name="roll" value="<?php echo $rollno; ?>"/>
physics <input type="text" name="phy" value="<?php echo $physics; ?>"/>
chemestry<input type="text" name="che" value="<?php echo $chemestry; ?>"/>
math <input type="text" name="math" value="<?php echo $math; ?>"/>
<input type="submit" value="save" class="man"/>
<input type="reset" value="clear"/>



</div>



</form>

</body>
</html>

&nbsp;

&nbsp;

The next post will illustrate searching.

 

 

Leave a Reply