3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function display_table(){ global $mysqli; $phpself = $_SERVER["PHP_SELF"]; $user = $_SESSION['user']; echo<<<TABLE <html> <head> <title>Insert new record</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]--> <script src="js/jquery.min.js"></script> <script src="js/jquery.dropotron.min.js"></script> <script src="js/skel.min.js"></script> <script src="js/skel-layers.min.js"></script> <script src="js/init.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css-table.css" /> <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script> <script type="text/javascript" src="js/style-table.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> jQuery.expr[':'].contains = function(a,i,m){ return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0; }; $(document).ready(function(){ $('input[name="search"]').keyup(function(){ var searchterm = $(this).val(); if(searchterm.length >2) { var match = $('tr.data-row:contains("' + searchterm + '")'); var nomatch = $('tr.data-row:not(:contains("' + searchterm + '"))'); match.addClass('selected'); nomatch.css("display", "none"); } else { $('tr.data-row').css("display", ""); $('tr.data-row').removeClass('selected'); } }); }); </script> <noscript> <link rel="stylesheet" href="css/skel.css" /> <link rel="stylesheet" href="css/style.css" /> <link rel="stylesheet" href="css/style-noscript.css" /> </noscript> <!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]--> <!--[if lte IE 9]><link rel="stylesheet" href="css/ie/v9.css" /><![endif]--> </head> <body class="no-sidebar loading"> <!-- Header --> <header id="header"> <h1 id="logo"><a href="home.php">HOME <span>PAGE</span></a></h1> <nav id="nav"> <ul> <li class="current"><a href="home.php">Welcome, $user</a></li> <li class="submenu"> <a href="">Options</a> <ul> <li class="submenu"> <a href="">View Database</a> <ul> <li><a href="example.php">Prospects </a></li> <li><a href="clients.php">Clients </a></li> </ul> </li> <li><a href="excel.php">Download report</a></li> <li class="submenu"> <a href="">Add Record</a> <ul> <li><a href="import.php">Import file</a></li> </ul> </li> <li><a href="backup.php">Backup Database</a></li> <li><a href="restore.php">Import Database</a></li> </ul> </li> <li> <a href="index.php" class="button special">Sign Out </a></li> </ul> </nav> </header> <!-- Main --> <article id="main"> <header class="special container"> <span class="icon fa-mobile"></span> <h2>Backup Database Files</h2> <p></p> </header> <!-- One --> <section class="wrapper style4 container"> <form action="$phpself" method="post"> <center>Choose Type : &nbsp; <select name='type'> <option>prospects</option> <option>clients</option> </select><br/><br/><input type="submit" name="submit" value="Backup SQL Database Now"> </center><br/> </form> </section> <!-- Two --> </article> <!-- Footer --> <footer id="footer"> <ul class="icons"> <li><a href="#" class="icon circle fa-twitter"><span class="label">Twitter</span></a></li> <li><a href="#" class="icon circle fa-facebook"><span class="label">Facebook</span></a></li> <li><a href="#" class="icon circle fa-google-plus"><span class="label">Google+</span></a></li> <li><a href="#" class="icon circle fa-github"><span class="label">Github</span></a></li> <li><a href="#" class="icon circle fa-dribbble"><span class="label">Dribbble</span></a></li> </ul> <span class="copyright">&copy; Untitled. All rights reserved. Design: <a href="http://html5up.net">HTML5 UP</a>.</span> </footer> </body> </html> TABLE; } function badinput($msg){ echo <<<BADINPUT <html> <head> <title>Bad input</title> </head> <body> <h1>Error</h1> <p>Input could not be used because $msg.</p> </body> </html> BADINPUT; } // CLEAN QUERIES function clean($str) { if(@isset($str)){ $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } else{ return 'NULL'; } } // DATABASE BACKUP CREATING FUNCTION function backup_Database($hostName,$userName,$password,$DbName,$tables = '*') { // CONNECT TO THE DATABASE $con = mysql_connect($hostName,$userName,$password) or die(mysql_error()); mysql_select_db($DbName,$con) or die(mysql_error()); // GET ALL TABLES if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } $return = 'SET FOREIGN_KEY_CHECKS=0;' . "\r\n"; $return.= 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";' . "\r\n"; $return.= 'SET AUTOCOMMIT=0;' . "\r\n"; $return.= 'START TRANSACTION;' . "\r\n"; foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table) or die(mysql_error()); $num_fields = mysql_num_fields($result) or die(mysql_error()); $data.= 'DROP TABLE IF EXISTS '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $data.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i<$num_fields; $i++) { while($row = mysql_fetch_row($result)) { $data.= 'INSERT INTO '.$table.' VALUES('; for($x=0; $x<$num_fields; $x++) { $row[$x] = addslashes($row[$x]); //$row[$x] = ereg_replace("\n","\\n",$row[$x]); $row[$x] = clean($row[$x]);// CLEAN QUERIES if (isset($row[$x])) { $data.= '"'.$row[$x].'"' ; } else { $data.= '""'; } if ($x<($num_fields-1)) { $data.= ','; } } // end of the for loop 2 $data.= ");\n"; } // end of the while loop } // end of the for loop 1 $data.="\n\n\n"; } // end of the foreach*/ $return .= 'SET FOREIGN_KEY_CHECKS=1;' . "\r\n"; $return.= 'COMMIT;'; //SAVE THE BACKUP AS SQL FILE $handle = fopen($DbName.'-Database-Backup-'.$table.date('Y-m-d @ h-i-s').'.sql','w+'); fwrite($handle,$data); fclos($handle); /* gz format $gzdata = gzencode($data, 9); $handle = fopen($DbName.'-Database-Backup-'.date('Y-m-d @ h-i-s').'.sql.gz','w+'); fwrite($handle, $gzdata); fclose($handle);*/ if($data) return true; else return false; } // end of the function function addnewdata(){ global $mysqli; $utype = $_POST["type"]; $tables = $utype; $backup_response = backup_Database('test','test','test','user',$tables); if($backup_response) { echo <<<SUCCESSRESPONSE <html> <head> <title>New record inserted</title> </head> <body> <h1>Database Backup Successfully Created!</h1> <p>Please wait, link will be auto redirected</p> <script>setTimeout(function(){window.location.href='backup.php'},4000);</script> </body> </html> SUCCESSRESPONSE; } else { echo 'Errors in Database Backup Creating!'; } } session_cache_limiter ('private, must-revalidate'); $cache_limiter = session_cache_limiter(); // session_cache_expire(60); // 60 minutes session_start(); $user = $_SESSION['user']; function connectToDatabase(){ global $mysqli; $mysqli = new mysqli('ptjobstation.com','csci311','020809','user'); // Check for connection errors if(mysqli_connect_errno()){ $problem = mysqli_connect_error(); badinput($problem); exit; } } $method = $_SERVER["REQUEST_METHOD"]; if($method=="POST"){ addnewdata(); } else{ display_table(); } ?>
Output for 5.3.0 - 7.1.0
Notice: Undefined index: user in /in/Ugk95 on line 285 Notice: Undefined index: REQUEST_METHOD in /in/Ugk95 on line 298 Notice: Undefined index: user in /in/Ugk95 on line 6 <html> <head> <title>Insert new record</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]--> <script src="js/jquery.min.js"></script> <script src="js/jquery.dropotron.min.js"></script> <script src="js/skel.min.js"></script> <script src="js/skel-layers.min.js"></script> <script src="js/init.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css-table.css" /> <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script> <script type="text/javascript" src="js/style-table.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> jQuery.expr[':'].contains = function(a,i,m){ return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0; }; $(document).ready(function(){ $('input[name="search"]').keyup(function(){ var searchterm = $(this).val(); if(searchterm.length >2) { var match = $('tr.data-row:contains("' + searchterm + '")'); var nomatch = $('tr.data-row:not(:contains("' + searchterm + '"))'); match.addClass('selected'); nomatch.css("display", "none"); } else { $('tr.data-row').css("display", ""); $('tr.data-row').removeClass('selected'); } }); }); </script> <noscript> <link rel="stylesheet" href="css/skel.css" /> <link rel="stylesheet" href="css/style.css" /> <link rel="stylesheet" href="css/style-noscript.css" /> </noscript> <!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]--> <!--[if lte IE 9]><link rel="stylesheet" href="css/ie/v9.css" /><![endif]--> </head> <body class="no-sidebar loading"> <!-- Header --> <header id="header"> <h1 id="logo"><a href="home.php">HOME <span>PAGE</span></a></h1> <nav id="nav"> <ul> <li class="current"><a href="home.php">Welcome, </a></li> <li class="submenu"> <a href="">Options</a> <ul> <li class="submenu"> <a href="">View Database</a> <ul> <li><a href="example.php">Prospects </a></li> <li><a href="clients.php">Clients </a></li> </ul> </li> <li><a href="excel.php">Download report</a></li> <li class="submenu"> <a href="">Add Record</a> <ul> <li><a href="import.php">Import file</a></li> </ul> </li> <li><a href="backup.php">Backup Database</a></li> <li><a href="restore.php">Import Database</a></li> </ul> </li> <li> <a href="index.php" class="button special">Sign Out </a></li> </ul> </nav> </header> <!-- Main --> <article id="main"> <header class="special container"> <span class="icon fa-mobile"></span> <h2>Backup Database Files</h2> <p></p> </header> <!-- One --> <section class="wrapper style4 container"> <form action="/in/Ugk95" method="post"> <center>Choose Type : &nbsp; <select name='type'> <option>prospects</option> <option>clients</option> </select><br/><br/><input type="submit" name="submit" value="Backup SQL Database Now"> </center><br/> </form> </section> <!-- Two --> </article> <!-- Footer --> <footer id="footer"> <ul class="icons"> <li><a href="#" class="icon circle fa-twitter"><span class="label">Twitter</span></a></li> <li><a href="#" class="icon circle fa-facebook"><span class="label">Facebook</span></a></li> <li><a href="#" class="icon circle fa-google-plus"><span class="label">Google+</span></a></li> <li><a href="#" class="icon circle fa-github"><span class="label">Github</span></a></li> <li><a href="#" class="icon circle fa-dribbble"><span class="label">Dribbble</span></a></li> </ul> <span class="copyright">&copy; Untitled. All rights reserved. Design: <a href="http://html5up.net">HTML5 UP</a>.</span> </footer> </body> </html>