Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="name">
- <?php
- $sql = "SELECT * FROM input";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- $index = 0;
- while($row = $result->fetch_assoc()) {
- $index++;
- ?>
- <div id="q">
- <?php echo $row["question"]; ?> </B>
- <?php
- echo '<button class="add" id="add_'.$index.'"><B>Add Answer</B></button>';
- echo '<form style="display:none;" name="answer_'.$index.'" method="post" action="output.php">'; // I dont think openning form from row to row would be nice!
- echo '<textarea type="text" class="addtext" name="addtext" required id="addtext_'.$index.'" placeholder="Please type your answer here.." ></textarea>';
- echo '<button onClick="addsubmit('.$index.');" type="submit" id="addsubmit_'.$index.'" class="addsubmit"><B>Submit</B></button>';
- echo '</form>';
- ?>
- <small><p><?php echo $row["date"]; ?></p></small>
- <?php include('1.php'); ?>
- <?php
- $servername = "localhost";
- $dbusername = "root";
- $dbpassword = "******";
- $dbname = "the_database";
- $addtext = $_POST['addtext'];
- $date = date_default_timezone_set('Asia/Kolkata');
- $date = date('d/m/Y H:i:s');
- $conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO output (answer, date)
- VALUES ('$addtext', '$date')";
- if ($conn->query($sql) === TRUE) {
- echo '<script language="javascript">';
- echo 'alert("Your Answer has been Succesfully posted")';
- echo '</script>';
- echo '<a href="answer.php"></a>';
- }
- else {
- echo "ERROR" . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement