0% found this document useful (0 votes)
71 views3 pages

PHP (Run On XAMPP Server) Two Files 1 Insert - HTML 2 Index - PHP

1. Start the XAMPP control panel to start the Apache and MySQL services. Create a database and table in phpMyAdmin. 2. Save two files, insert.html and index.php, in a folder in the XAMPP htdocs folder. Insert.html contains a form to submit data. Index.php connects to the MySQL database and inserts the submitted data into the table. 3. Access insert.html via localhost to submit data via the form, which is then inserted into the MySQL table by index.php. Index.php then queries and displays the table data

Uploaded by

Samruddhi Jumale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views3 pages

PHP (Run On XAMPP Server) Two Files 1 Insert - HTML 2 Index - PHP

1. Start the XAMPP control panel to start the Apache and MySQL services. Create a database and table in phpMyAdmin. 2. Save two files, insert.html and index.php, in a folder in the XAMPP htdocs folder. Insert.html contains a form to submit data. Index.php connects to the MySQL database and inserts the submitted data into the table. 3. Access insert.html via localhost to submit data via the form, which is then inserted into the MySQL table by index.php. Index.php then queries and displays the table data

Uploaded by

Samruddhi Jumale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PHP (Run on XAMPP server)

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

1> Open firefox -> in address bar type->localhost\php1\insert.html


(php1-> is name of folder you had given)

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);

/*$sql= ' select * from user ' ;


$rs=mysqli_query($conn,$sql);
$nrows = mysqli_num_rows($rs);
if( $nrows > 0)
{
while($row=mysqli_fetch_assoc($rs))
{
echo "Name: {$row['name']}<br>";
echo "password: {$row['password']}<br>";
echo "-------------------------<br>";
}
}*/
$sql = "SELECT * FROM user";

$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()) {

echo "<tr>"."<th class=data>"."Username: ".$row["username"]."<br><br><br><br>


"."Password: ".$row["password"]."<br><br><br><br>"."</th></tr><br>";
}
echo "</table></form>";
} else {
echo "0 results";
}

/*else
{
echo "Record not found";
}*/
mysqli_close($conn);

?>

You might also like