<?php //set up for mysql Connection $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; //test if the connection is established successfully then it will proceed in next process else it will throw an error message if(! $conn ) { } //we specify here the Database name we are using //It wiil insert a row to our tblstudent` $sql = "INSERT INTO `studentdb`.`tblstudent` (`s_id`, `firstname`, `lastname`, `email`, `phone`) VALUES (NULL, 'Joken', 'Villanueva', '[email protected]', '09983344318');"; //we are using mysql_query function. it returns a resource on true else False on error if(! $retval ) { } echo "Entered data successfully\n"; //close of connection ?>
<html> <head> <title>Add Student Record</title> </head> <body> <form method="post" action="process_addstud.php"> <table width="400" border="0" cellspacing="1" cellpadding="2" align="center"> <th colspan="2" align="left">Add Student</h2> <tr> <td width="100">First Name</td> <td><input name="f_name" type="text" id="f_name"></td> </tr> <tr> <td width="100">Last Name</td> <td><input name="l_name" type="text" id="l_name"></td> </tr> <tr> <td width="100">Email</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td width="100">Contact</td> <td><input name="contact" type="text" id="contact"></td> </tr> <td width="100"> </td> <td> <input name="save" type="submit" id="save" value="Add Student"> </td> </tr> </table> </form> </body> </html>
<?php //set up for mysql Connection $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; //test if the connection is established successfully then it will proceed in next process else it will throw an error message if(! $conn ) { } //we specify here the Database name we are using $f_name = $_POST['f_name']; $l_name = $_POST['l_name']; $email = $_POST['email']; $contact= $_POST['contact']; //It wiil insert a row to our tblstudent` $sql = "INSERT INTO `studentdb`.`tblstudent` (`s_id`, `firstname`, `lastname`, `email`, `phone`) VALUES (NULL, '{$f_name}', '{$l_name}', '{$email}', '{$contact}');"; //we are using mysql_query function. it returns a resource on true else False on error if(! $retval ) { } ?> <script type="text/javascript"> alert("New Record is Added to the Database"); window.location = "addStudent.php"; </script> <?php //close of connection ?>