Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $output = 'status=ok';
- foreach($_POST as $key=>$value){
- $output .= "&$key=".urlencode($value);
- }
- //echo $output;
- $host = "localhost:8888";
- $user = "root";
- $password = "root";
- // connect to mysql
- $connection = mysql_connect($host, $user, $password) ;
- if (!$connection) {
- echo '&error=' . mysql_error() . '&';
- die('Could not connect ' . mysql_error());
- }
- // connect to db
- $database = 'comment';
- $db = mysql_select_db($database, $connection);
- if (!$db) {
- echo '&error=' . mysql_error() . '&';
- die ('Not connected : ' . mysql_error());
- }
- // get the records
- if ($numrows > 0) {
- $duplicate = 'Username is taken. Please choose another.';
- echo '&duplicate=y&message=' . urlencode($duplicate);
- }else{
- $numrows = mysql_num_rows($result);
- $query = "INSERT INTO comment (comment_field)
- VALUES ('" . $_POST['commentfield'] . "')";
- //echo $query;
- $result = mysql_query($query, $connection);
- }
- //$_POST['commentfield'] = "hello"; //debugging purpose
- // query
- //$query = "SELECT * FROM comment";
- //$resultID = mysql_query($query, $connection);
- if (!$result) {
- echo '&error=' . mysql_error() . '&';
- die ('Invalid query: ' . mysql_error());
- }
- $xml_output = "<?xml version=\"1.0\"?>\n";
- $xml_output .= "<entries>\n";
- for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
- $row = mysql_fetch_assoc($result);
- $xml_output .= "\t<entry>\n";
- $xml_output .= "\t\t<id>" . $row['id'] . "</id>\n";
- $xml_output .= "\t\t<timestamp>" . $row['timestamp'] . "</timestamp>\n";
- $xml_output .= "\t\t<comment_field>" . $row['comment_field'] . "</comment_field>\n";
- $xml_output .= "\t</entry>\n";
- }
- $xml_output .= "</entries>";
- echo $xml_output;
- mysql_close($connection);
- ?>
Add Comment
Please, Sign In to add comment