Comment créer une page téléchargeable c'est-à-dire imprimer après les données chargées du formulaire en php
1
Likes
0
Dislikes
Likes
Dislikes
1
Comments
Login to add comment
kabeer can't understand your question.
Please describe your issue.
Like
Added Jan 13, 05:39 pm
0 Likes
Reply
Show 1 more replies
1 Answers
Before starting code you need to create database and set connection between php and database.
Go to localhost and create a database named users and create a table under this database named userdata .

connection.php
<?php
$con = mysqli_connect('localhost', 'root', '', 'users');
if(!$con) {
die('connection not established.');
}
?>
index.php
<form method="post" action="addData.php">
<p><input type="text" placeholder="Enter Name" name="name"></p>
<p><input type="email" placeholder="Enter Email" name="email"></p>
<p><input type="number" placeholder="Enter Phone number" name="phnum"></p>
<p><button name="submit_form">Add data</button></p>
</form>
addData.php
<?php
// include connection
include('connection.php');
// check form data
if(isset($_POST['submit_form'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phnum = $_POST['phnum'];
$sql = "Insert into userdata(name, email, phnum) values('".$name."', '".$email."', '".$phnum."')";
if(mysqli_query($con, $sql)) {
header('location: showData.php');
}
else {
echo 'Data not inserted'. mysqli_error($con);
}
}
?>
showData.php
<?php
// include connection
include('connection.php');
// select all data from table
echo '<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Phone number</th>
</tr>
</thead>
<tbody>';
$sql = "Select * from userdata";
$query = mysqli_query($con, $sql);
if(mysqli_num_rows($query) > 0) {
while ($row = mysqli_fetch_array($query)) {
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['name'].'</td>
<td>'.$row['email'].'</td>
<td>'.$row['phnum'].'</td>
</tr>';
}
}
echo '</tbody>
</table>';
?>
Thank you.
0
Likes
0
Dislikes
Likes
Dislikes
0
Comments
Login to add comment