PHP (Run On XAMPP Server) Two Files 1 Insert - HTML 2 Index - PHP
PHP (Run On XAMPP Server) Two Files 1 Insert - HTML 2 Index - PHP
Two files
1> insert.html
2> index.php
Steps:->
1> Start ->programs->XAMPP->xampp control panel (check APACHE and MySQL has green tick and stop
is at button) minimize this window
2> Open firefox->write in address bar->localhost/phpmyadmin -> create database and table here,also
add at least 3 rows in it. (This is MYSQL)
Database name- db
Table name- stud
Table have 2 columns name,password with data type varchar
3> Goto My computer -> c:\ ->Xampp folder->htdoc folder-> in this folder create on folder named as
php1(any name you can give) in this folder save two files ->insert.html and index.php (write code in
these files using notepad)
To Run
insert.html
<html>
<body>
<form action="index.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="address"><br>
<input type="submit">
</form>
</body>
</html>
index.php
<?php
$conn=mysqli_connect('localhost','root','','userlogin'); //db is name of database created in mysql
phpmyadmin
if(!$conn)
{
die(mysqli_connect_error());
}
echo "connect successfully";
echo "<br>";
$tname= $_POST["name"];
$tadd=$_POST["password"];
$sql1="insert into user values ('$tname','$tadd')";
echo $sql1;
mysqli_query($conn,$sql1);
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
echo"<table align=center border=1><form>";
// output data of each row
while($row = $result->fetch_assoc()) {
/*else
{
echo "Record not found";
}*/
mysqli_close($conn);
?>