Jump to content

Recommended Posts

here is my form.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>My Post page</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>

    <section><!-- Header -->

        <h1>moriahtalk</h1>
       <h2>Speak your mind.</h2>

     <form action="demo.php" method="post">
    <textarea required name="text"  placeholder="Write Something..." id="text" cols="30" rows="10"></textarea>
<input type="submit" name="submit" value="button">
</form>
  </form>
</section>
</body>
</html>

and this is demo.php

<?php
$servername = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "forms";

$text = $_POST ['text'];
// Evaluate the connection
$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
//check connection
if ($conn->connect_error) {
    die("conection failed: " . $conn->connect_error);
}

if (empty($text)) {
    echo " This cannot be blank at all";

die ();
}

$sql = "INSERT INTO demo (text) VALUES ('$text')";
if ($conn->query($sql) ==TRUE) {
    
    echo " Your info has been submitted";
}
else {
    echo "error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>

when i submit data. it stores on the database. But I want to display that date on another page. please tell me how do I do this?

 

also how can I apply bootstrap and CSS to that page

 

 

Link to comment
https://forums.phpfreaks.com/topic/298841-need-to-display-data-form/
Share on other sites

After saving the data in the database, you need to retrieve the last inserted ID, and then redirect the user to another URL with that ID passed as some kind of parameter.

 

This other URL will then run a script that fetches the information back from the database using the ID passed in the URL, and then display it in some kind of template.

 

Individually they're all relatively simple things to do; just google them separately, and put the pieces together.

Edited by Adam
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.