I learned PHP from an institute but they taught me old syntax and techniques for PHP inserting data into database. When i searched online it found it deprecated and will not be longer available in future version of PHP.I want to learn the new techniques for inserting data into database. I give you example what i am doing now, it is working fine for me but i want to insert data using prepared statement and all possible techniques.
HTML:
<form method="post" action="do_submit.php"/>
Name:<input type="text" name="name" id="name"/>
Class:<input type="text" name="class" id="class"/>
Section:<input type="text" name="section" id="section"/>
Roll Number:<input type="text" name="roll" id="roll"/>
Registration Number:<input type="text" name="reg" id="reg"/>
<input type="submit"/>
</form>
do_submit.php:
<?php
include 'dbconnect.php';
$name=$_POST['name'];
$class=$_POST['class'];
$section=$_POST['section'];
$roll=$_POST['roll'];
$reg=$_POST['reg'];
$sql = mysql_query("INSERT INTO `school`.`students` (`Name`, `Class`, `Section`,`Roll_No`, `Reg_No`)
VALUES ('$name', '$class', '$section', '$roll','$reg');") or die("SELECT Error: ".mysql_error());
if($sql)
{
$myURL = 'success.php?sType=insert';
header('Location: '.$myURL);
exit;
}
else
echo "Try again!";
?>
Can anyone please guide me with example code so that i learn new techniques that are more secured from being hacked.