By using this i get backup of a table but i need to get new data in the backup table and i don't need old data

<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<link rel="icon" type="image/png" href="assets/img/favicon.ico">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

	<title>RESTAURANT MANAGEMENT</title>

	<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
    <meta name="viewport" content="width=device-width" />


    <!-- Bootstrap core CSS     -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" />

    <!-- Animation library for notifications   -->
    <link href="assets/css/animate.min.css" rel="stylesheet"/>

    <!--  Light Bootstrap Table core CSS    -->
    <link href="assets/css/light-bootstrap-dashboard.css" rel="stylesheet"/>


    <!--  CSS for Demo Purpose, don't include it in your project     -->
    <link href="assets/css/demo.css" rel="stylesheet" />


    <!--     Fonts and icons     -->
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
    <link href="assets/css/pe-icon-7-stroke.css" rel="stylesheet" />
	<style>
	.tot
	{
		font-size:25px;
		font-family:Roboto Slab Bold;
		color:#fff;		
	}
	.tot1
	{
		font-size:20px;
		color:#FFF;	
	}
	.card .title
	{
		color:#fff;
	}
	</style>
</head>
<body>
<div class="wrapper">
    <div class="sidebar" data-color="purple" data-image="assets/img/sidebar-5.jpg">

    <!--   you can change the color of the sidebar using: data-color="blue | azure | green | orange | red | purple" -->


    	<div class="sidebar-wrapper">
            <div class="logo">
                <a href="#" class="simple-text">
                   MANAGEMENT
                </a>
            </div>

            <ul class="nav">
                <li>
                    <a href="dashboard.php">
                        <i class="pe-7s-graph"></i>
                        <p>Dashboard</p>
                    </a>
                </li>
                <li>
                    <a href="month.php">
                        <i class="pe-7s-user"></i>
                        <p>Monthly Reports</p>
                    </a>
                </li>
                <li>
                    <a href="ktm.php">
                        <i class="pe-7s-note2"></i>
                        <p>KTM Reports</p>
                    </a>
					<li class="active">
                    <a href="backup.php">
                        <i class="pe-7s-note"></i>
                        <p>IMPORT EXPORT</p>
                    </a>
                </li>
            </ul>
    	</div>
    </div>

    <div class="main-panel">
		<nav class="navbar navbar-default navbar-fixed">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-example-2">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">Import Export</a>
                </div>
                <div class="collapse navbar-collapse">
                    <ul class="nav navbar-nav navbar-left">
                        <li>
                            <a href="logout.php">
                                <p>Log out</p>
                            </a>
                        </li>
						<li class="separator hidden-lg hidden-md"></li>
                    </ul>
                </div>
            </div>
        </nav>
		<div class="content">
		<div class="container">
		<div class="col-md-8">
		<div class="card" style="padding:40px 10%;">
<?php
//error_reporting(0);
/*$conn=mysqli_connect("120.138.8.94","jebzi_gh","GCAF@lc0n2015");
mysqli_select_db($conn,'jebzin_gh') or die(mysqli_error($conn));
include('config.php');
*/
$con1=mysqli_connect("localhost","root","root");
mysqli_select_db($con1,'jebzin_gc') or die(mysqli_error($con1));
$sql=mysqli_query($con1,'SHOW TABLES') or die(mysqli_error($con));
?>
<form action="" method="post">
<label><b style="color:#000;" >Choose your Table to export</b></label>
<select name="pick" class="form-control">
    <option value=" ">SELECT</option>
		<?php
        while($res=mysqli_fetch_array($sql))
        {?>
	        <option value="<?php echo $res[0]; ?>"><?php echo $res[0]; ?></option>
        <?php
        }
		mysql_close($con1);
        ?>
</select><br/>
<input type="submit" name="export" value="EXPORT" class="btn btn-default" style="margin-bottom:15px;border-color:#B03FFF;color:#B03FFF;"><br/>
<label><b style="color:#000;">Choose your Table to import</b></label>
<input type="file" name="choose" value="CHOOSE" ><br/>
<input type="submit" name="import" value="IMPORT" class="btn btn-default" style="margin-bottom:40px;border-color:#B03FFF;color:#B03FFF;">
</form>
<?php
if(isset($_POST['export']))
{
	/*
	$tableName  = $_POST['pick'];
	$backupFile = "www/".$_POST['pick'].".sql";
	$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
	$result = mysqli_query($con1,$query) or die(mysqli_error($con)); 
	if($result)
	{
		echo "<script>alert('Exported Successfully')</script>";
	}
	else
	{
		echo "<script>alert('Failed to Export')</script>";
	} */
	
	/*
	 $con1=mysqli_connect("localhost","root","root");
	 mysqli_select_db($con1,'jebzin_gh') or die(mysqli_error($con1));
	 $table_name =  $_POST['pick'];
	 $backup_file  =  $_POST['pick'] .".sql";
	 echo $sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";	
	 $retval = mysqli_query( $con1  ,$sql);	
	 if(! $retval ) {
	  die('Could not take data backup: ' . mysql_error());
	 }	
	 echo "Backedup  data successfully\n";	
	 mysql_close($con1); */
	
	/*
	$dbhost = 'localhost';
	$dbuser = 'root';
	$dbpass = 'root';
	$dbname = 'jebzin_gh';
	$mysqldump=exec('which mysqldump');
	$command = "$mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname > $dbname.sql";
	exec($command);	
	*/
	
	
	$link = mysqli_connect('localhost','root','root','jebzin_gh');
//	mysql_select_db('jebzin_gh',$link);
//	$tables='bill,bill_details';
	$tables = $_POST['pick'];
	//get all of the 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="";
	//cycle through
	foreach($tables as $table)
	{
		$result = mysqli_query($link , 'SELECT * FROM '.$table);
		$num_fields = mysqli_num_fields($result);
		
		$return.= 'DROP TABLE '.$table.';';
		$row2 = mysqli_fetch_row(mysqli_query($link,'SHOW CREATE TABLE '.$table));
		$return.= "\n\n".$row2[1].";\n\n";
		
		for ($i = 0; $i < $num_fields; $i++) 
		{
			while($row = mysqli_fetch_row($result))
			{
				$return.= 'INSERT INTO '.$table.' VALUES(';
				for($j=0; $j < $num_fields; $j++) 
				{
					$row[$j] = addslashes($row[$j]);
					$row[$j] = str_replace("\n","\\n",$row[$j]);
					if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
					if ($j < ($num_fields-1)) { $return.= ','; }
				}
				$return.= ");\n";
			}
		}
		$return.="\n\n\n";
	}
	
	//save file
	$handle = fopen('db-backup-'.time().'-'.(implode(',',$tables)).'.sql','w+');
	fwrite($handle,$return);
	fclose($handle);

	/*
	
	 if(! $con1 ) {
	  die('Could not connect: ' . mysql_error());
	 }	
	 $table_name =  $_POST['pick'];
	 $backup_file  =  $_POST['pick'] .".sql";
	 echo $sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";	
	 $retval = mysql_query( $sql, $con1 );	
	 if(! $retval ) {
	  die('Could not take data backup: ' . mysql_error());
	 }	
	 echo "Backedup  data successfully\n";	
	 mysql_close($con1); */
}
?>
<?php
if(isset($_POST['import']))
{   /*
	$tableName  = $_POST['choose'];
	$backupFile =  "www/".$_POST['choose'];
	//$backupFile = "bill.sql";
	//$query      = "LOAD DATA INFILE '$backupFile' INTO TABLE $tableName";
	$query = "select * from bill";
	print_r($conn);
	$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
	while($res=mysqli_fetch_array($result))
	{
		echo $res[0]."</br>";
	}
	if($result)
	{
		echo "<script>alert('Imported Successfully')</script>";
	}
	else
	{
		echo "<script>alert('Failed to Import')</script>";
	} */
	
	if(isset($_POST['choose']))
	{
		if($_POST['choose']!= "")
		{
			// Dear karthik kindly set perfect dynamic path to bellow variable for $filename.
			$filename = $_POST['choose'];
			$mysql_host = '120.138.8.94';
			$mysql_username = 'jebzi_gh';
			$mysql_password = 'GCAF@lc0n2015';
			$mysql_database = 'jebzin_gh';
			
			mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
			mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());
			$templine = '';
			$lines = file($filename);
			foreach ($lines as $line)
			{
				if (substr($line, 0, 2) == '--' || $line == '')
					continue;
				$line = str_replace('INSERT','REPLACE',$line);
				$templine .= $line;
				if (substr(trim($line), -1, 1) == ';')
				{
					mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
					$templine = '';
				}
			}
			 echo "Tables imported successfully";
		}
		else
		{
			 echo "Kindly choose table.";
		}
	}
	else
	{
		 echo "Kindly choose table.";
	}
}
?>
</div>
</div>
</div>
</div> 	
<footer class="footer">
            <div class="container-fluid">

                <p class="copyright pull-right">
                    &copy; <script>document.write(new Date().getFullYear())</script> <a href="#">Restaurant management</a>,  website powered by Falcon square | Coimbatore	
                </p>
            </div>
        </footer>

Can you explain the problem in a bit more detail? “I need to get new data in the backup table and I don’t need old data” - how do you define what is new and what is old data? Can you narrow it down and just post the (formatted) code for the section that you need help with, rather than all of it?

Is there any reason you mix between mysqli and mysql functions in the same code?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.