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. -->
<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="" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;style&gt;" title="&lt;style&gt;" />


<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"/>






The next post will illustrate searching.



Leave a Reply