Jump to content

Escee

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by Escee

  1. Escee

    MySQL query to XML

    Hi,I'm currently testing a bit with XML. Now I made this script that returns a XML file from the fetched MySQL query. But the thing is that the XML output doesn't look really tidy. So, I could add some tabs and stuff. But maybe is there a easier way with SimpleXML or something. I tried some stuff, but that didn't work out...Maybe you can help? This is my current code: <?php error_reporting ( E_ALL | E_STRICT ); /* * XML headers meegeven zodat XSL er wat mee kan. */ header ( 'Content-type: text/xml' ); /* * De variable waarmee de tabel kan worden aan- * gevraagd controleren. */ $get_table = $_GET [ 'table' ]; $possible_tables = array ( 'blogs' ); if ( empty ( $get_table ) ) { exit ( 'Er is geen $_GET [ \'table\' ] variabele gevonden.' ); } else if ( !in_array ( $get_table, $possible_tables ) ) { exit ( 'De $_GET [ \'table\' ] variabele bevat incorrecte data.' ); } /* * Verbinding met de MySQL server maken. */ $mysql_login = array ( 'mysql_user' => 'root', 'mysql_pass' => '123456', 'mysql_db' => 'escee' ); extract ( $mysql_login ); if ( !mysql_connect ( 'localhost', $mysql_user, $mysql_pass ) ) { exit ( 'De MySQL login gegevens zijn incorrect.' ); } else if ( !mysql_select_db ( $mysql_db ) ) { exit ( 'De opgevraagde database bestaat niet.' ); } /* * De query uitvoeren voor de gegevens die nodig zijn. */ $mysql_query = ' SELECT time, entry, title FROM ' . $get_table . ' ORDER BY blogs.time DESC LIMIT 0, 5 '; if ( !$mysql_result = mysql_query ( $mysql_query ) ) { exit ( 'De MySQL query bevat een error; ' . mysql_error ( ) . '.' ); } else if ( mysql_num_rows ( $mysql_result ) == 0 ) { exit ( 'De MySQL query bevat geen rijen.' ); } /* * De query uitpakken en in een XML string gooien. */ $xml_array = array ( ); while ( $mysql_row = mysql_fetch_assoc ( $mysql_result ) ) { $xml_array [ ] = '<' . substr ( $get_table, 0, -1 ) . '>'; foreach ( $mysql_row as $mysql_field => $mysql_value ) { if ( $mysql_field { 0 } != '_' ) { $xml_array [ ] = '<' . $mysql_field . '>' . $mysql_value . '</' . $mysql_field . '>'; } } $xml_array [ ] = '</' . substr ( $get_table, 0, -1 ) . '>'; } /* * De array met XML data weergeven. */ $xml_output = '<?xml version=\'1.0\' encoding=\'UTF-8\' ?> <' . $get_table . '>'; foreach ( $xml_array as $xml_item ) { $xml_output .= $xml_item . "\n"; } echo $xml_output . '</' . $get_table . '>'; ?> I hope you don't mind the dutch comments and exit errors :)Thanks
  2. Escee

    $_POST

    Also.. hidden fields are great for hackers 'cause you can edit them with external PHP scripts that 'opens' your website and send these forms.
  3. $rules = explode ( "\n", $regex_output );foreach ( $rules as $id => $rule ){ echo $id . ': ' . $rule . '<br/>';}
×
×
  • Create New...