Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <div class="name">
  2. <?php
  3. $sql = "SELECT * FROM input";
  4. $result = $conn->query($sql);
  5. if ($result->num_rows > 0) {
  6. $index = 0;
  7. while($row = $result->fetch_assoc()) {
  8. $index++;
  9. ?>
  10.  
  11. <div id="q">
  12. <?php echo $row["question"]; ?> </B>
  13. <?php
  14. echo '<button class="add" id="add_'.$index.'"><B>Add Answer</B></button>';
  15.  
  16.  
  17.  
  18.  
  19. 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!
  20. echo '<textarea type="text" class="addtext" name="addtext" required id="addtext_'.$index.'" placeholder="Please type your answer here.." ></textarea>';
  21. echo '<button onClick="addsubmit('.$index.');" type="submit" id="addsubmit_'.$index.'" class="addsubmit"><B>Submit</B></button>';
  22. echo '</form>';
  23. ?>
  24. <small><p><?php echo $row["date"]; ?></p></small>
  25.  
  26. <?php include('1.php'); ?>
  27. <?php
  28. $servername = "localhost";
  29. $dbusername = "root";
  30. $dbpassword = "******";
  31. $dbname = "the_database";
  32. $addtext = $_POST['addtext'];
  33. $date = date_default_timezone_set('Asia/Kolkata');
  34. $date = date('d/m/Y H:i:s');
  35. $conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
  36. if ($conn->connect_error) {
  37. die("Connection failed: " . $conn->connect_error);
  38. }
  39. $sql = "INSERT INTO output (answer, date)
  40. VALUES ('$addtext', '$date')";
  41. if ($conn->query($sql) === TRUE) {
  42. echo '<script language="javascript">';
  43. echo 'alert("Your Answer has been Succesfully posted")';
  44. echo '</script>';
  45. echo '<a href="answer.php"></a>';
  46. }
  47. else {
  48. echo "ERROR" . $sql . "<br>" . $conn->error;
  49. }
  50. $conn->close();
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement