Comment créer une page téléchargeable c'est-à-dire imprimer après les données chargées du formulaire en php

Asked  Jan 12, 08:21 pm 48 Views Add Your Answer
Asked  Jan 12, 08:21 pm
Php
0 Dislikes
1 Comments
kabeer can't understand your question. Please describe your issue.
Added  Jan 13, 05:39 pm

1 Answers

Edited  Jan 14, 12:13 am

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 .

Localhost PhpMyAdmin

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
0 Comments
×
SignUp with Email
X