如何将我在表单中发布的标题转换为html和php中的自动可点击链接?

如何将我在表单中发布的标题转换为html和php中的自动可点击链接?,php,html,mysql,Php,Html,Mysql,我将标题作为用户的输入,并将其发布到mysql数据库中。我想要的是,当我再次显示该数据时,它应该是一个超链接,以便我可以单击该标题,然后进行评论 我正在写的代码:- take.php <?php ?> <!DOCTYPE HTML> <html> <head> <title>Ask-Free/Your Account</title> <link rel="stylesheet" type="text/css" hr

我将标题作为用户的输入,并将其发布到mysql数据库中。我想要的是,当我再次显示该数据时,它应该是一个超链接,以便我可以单击该标题,然后进行评论

我正在写的代码:-

take.php

<?php
?>

<!DOCTYPE HTML>
<html>
<head>
<title>Ask-Free/Your Account</title>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body id="hello">

   <div id="heading">
       <table  border="0" style="width: 100%" cellspacing=".5">

               <tr>
               <td>
           <h1 style="color:#fffaf0">
               <i>ASK-FREE</i>
        </h1>
               </td>
               <td>
                   <form>
                                <input div class="search" type="text" placeholder="Search Your Question Here">
                                <input div class="button" type="button" value="Ask Question">
                    </form>
               </td>

               <div class="username">
               <td><h4 style="color:white">Welcome </h4></td>
               <td><a div class="a" style="color: white" href="logout.php" target="_blank">Home</a></td>
                <td>
                  <a div class="a" style="color: white" href="accountsetting.php" target="_blank">Account Settings</a>

              </td>
               <td><a div class="a" style="color: white" href="logout.php" target="_blank">Log Out</a></td>

               <td><a div class="a" style="color: white" href="Help.php" target="_blank">Need Help?</a></td>

       </tr>

       </table>
   </div>
    </div>
    <div id="second">
        <h2 style="color: white">
            <center> ASK YOUR QUESTION!</center>
        </h2>
    </div>


    <div class="recent">
        <h2 style="color:black" div class="b">ASK YOUR QUESTION HERE</h2>
        <br>
        <form action="post.php" method="POST">
        <p style="color:black">TITLE<br><input div class="c" type="text" id="title" name="title">
        <br>
        <br>
        <br>
        DESCRIPTION<br><textarea div class="d" name="description" id="description" >
        </textarea>
            <br>
            <br>
            <input div class="button2" type="submit"  value="POST">
        </form>
    </div>


    <div class="new">
        <h2 style="color:black" div class="e">RECENTLY ASKED QUESTIONS</h2>
        <br>
        <br>

        <?php
echo "<table style='border: solid 1px solid black;'>";
echo "<tr><th>SERIAL NO.</th><th>TITLE</th><th>DESCRIPTION</th><th>DATE</th></tr>";

class TableRows extends RecursiveIteratorIterator { 
    function __construct($it) { 
        parent::__construct($it, self::LEAVES_ONLY); 
    }

    function current() {
        return "<td style='width:250px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() { 
        echo "<tr>"; 
    } 

    function endChildren() { 
        echo "</tr>" . "\n";
    } 
} 

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shubhamyadav";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare("SELECT id,title,description,date FROM questions"); 
    $stmt->execute();

    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
        echo $v;
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

    </div>


    <div id="footer">
        <table border="0" style="width: 100%" cellspacing="-0.2">
            <td>
            <tr>
                <td style="color: white">Ask-Free,Inc 2015</td>
                <td style="color: white">User Agreement</td>
                <td style="color: white">Privacy Policy</td>
                <td style="color: white">Community Guidelines</td>
            <td style="color: white">Created by Shubham Yadav</td>
            <td style="color: white">Terms & conditions</td>
            <td style="color: white">Contact Us</td>
                <td style="color: white">Ad Choices</td>
                <td style="color: white">Cookie Policy</td>
                <td style="color: white">Hyperlinking  Policy</td>
                <td style="color: white">Copyright Policy</td>
            </tr>
        </td>
        </table>
    </div> 
     </body>
</html> 

问免费/你的帐户
免费询问
欢迎
问你的问题!
在这里问你的问题

标题



说明


最近提出的问题


这个标题应该链接到哪里?这个标题应该链接到答案页面…与这个标题相关的答案将发布在哪里…以及你的链接应该如何构建?我的意思是,你在某处有答案ID吗?是的,我在一个名为“答案”的表中有它…这个标题应该链接到哪里?这个标题应该链接到答案页面…与这个标题相关的答案将发布在哪里…以及你的链接应该如何构建?我的意思是,你有答案ID吗?是的,我在一个名为答案的表格中有答案ID。。。
<?php
/*** begin our session ***/
session_start();

/*** first check that both the username, password and form token have been sent ***/
if(!isset( $_POST['title'],$_POST['description']))
{
    echo 'Enter A Valid Title And Description To Your Question';
}
/*** check the form token is valid ***/
/*** check the username is the correct length ***/
elseif (strlen( $_POST['title']) > 255 || strlen($_POST['title']) < 1)
{
    echo 'You Must Add A valid title';
}
/*** check the password is the correct length ***/

else
{
    /*** if we are here the data is valid and we can insert it into database ***/

    $title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
    $description = filter_var($_POST['description'], FILTER_SANITIZE_STRING);
    $date = date('y-m-d');
    /*** now we can encrypt the password ***/


    /*** connect to database ***/
    /*** mysql hostname ***/
    $mysql_hostname = 'localhost';

    /*** mysql username ***/
    $mysql_username = 'root';

    /*** mysql password ***/
    $mysql_password = '';

    /*** database name ***/
    $mysql_dbname = 'shubhamyadav';

    try
    {
        $dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
        /*** $message = a message saying we have connected ***/

        /*** set the error mode to excptions ***/
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        /*** prepare the insert ***/
        $stmt = $dbh->prepare("INSERT INTO questions (title,description,date) VALUES (:title,:description,:date)");

        /*** bind the parameters ***/

        $stmt->bindParam(':title', $title, PDO::PARAM_STR);
        $stmt->bindParam(':description', $description, PDO::PARAM_STR);
         $stmt->bindParam(':date', $date, PDO::PARAM_STR);


        /*** execute the prepared statement ***/
        $stmt->execute();

        /*** unset the form token session variable ***/

        header('location:afterpost.php');
        /*** if all is done, say thanks ***/

    }
    catch(Exception $e)
    {
        /*** check if the username already exists ***/
        if( $e->getCode() == 23000)
        {
            echo 'Question Already Exist';
        }
        else
        {
            /*** if we are here, something has gone wrong with the database ***/
            echo 'We are unable to process your request. Please try again later';
        }
    }
}
?>