Guest User

Untitled

a guest
Jul 3rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php
  2. $output = 'status=ok';
  3. foreach($_POST as $key=>$value){
  4. $output .= "&$key=".urlencode($value);
  5. }
  6. //echo $output;
  7.  
  8. $host = "localhost:8888";
  9. $user = "root";
  10. $password = "root";
  11.  
  12.  
  13. // connect to mysql
  14. $connection = mysql_connect($host, $user, $password) ;
  15. if (!$connection) {
  16. echo '&error=' . mysql_error() . '&';
  17. die('Could not connect ' . mysql_error());
  18. }
  19.  
  20. // connect to db
  21. $database = 'comment';
  22. $db = mysql_select_db($database, $connection);
  23. if (!$db) {
  24. echo '&error=' . mysql_error() . '&';
  25. die ('Not connected : ' . mysql_error());
  26. }
  27.  
  28. // get the records
  29. if ($numrows > 0) {
  30. $duplicate = 'Username is taken. Please choose another.';
  31. echo '&duplicate=y&message=' . urlencode($duplicate);
  32. }else{
  33. $numrows = mysql_num_rows($result);
  34. $query = "INSERT INTO comment (comment_field)
  35. VALUES ('" . $_POST['commentfield'] . "')";
  36. //echo $query;
  37. $result = mysql_query($query, $connection);
  38. }
  39.  
  40.  
  41. //$_POST['commentfield'] = "hello"; //debugging purpose
  42.  
  43. // query
  44. //$query = "SELECT * FROM comment";
  45. //$resultID = mysql_query($query, $connection);
  46. if (!$result) {
  47. echo '&error=' . mysql_error() . '&';
  48. die ('Invalid query: ' . mysql_error());
  49. }
  50.  
  51. $xml_output = "<?xml version=\"1.0\"?>\n";
  52. $xml_output .= "<entries>\n";
  53.  
  54. for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
  55. $row = mysql_fetch_assoc($result);
  56. $xml_output .= "\t<entry>\n";
  57. $xml_output .= "\t\t<id>" . $row['id'] . "</id>\n";
  58. $xml_output .= "\t\t<timestamp>" . $row['timestamp'] . "</timestamp>\n";
  59. $xml_output .= "\t\t<comment_field>" . $row['comment_field'] . "</comment_field>\n";
  60. $xml_output .= "\t</entry>\n";
  61. }
  62.  
  63. $xml_output .= "</entries>";
  64.  
  65. echo $xml_output;
  66.  
  67.  
  68.  
  69. mysql_close($connection);
  70. ?>
Add Comment
Please, Sign In to add comment