I am sure errors similar to this have been posted. I dug around a bit and found nothing that helped me.
I am extremely new to PHP/HTML etc... however I have done a little coding with Java and C++ in the past.
For the end game I am trying to create a script that will let me access phpmyadmin and download tables each to its own individual CSV file.
The only thing I can find anywhere close to this is this one:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
$user =$_POST['user'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MySql to CSV script by www.erriko.it</title>
<style type="text/css">
body{
background:#dedede;
margin:0;
padding:0;
}
#wrapper{
width:100%;
}
#form{
margin-left:auto;
margin-right:auto;
margin-top:100px;
width:400px;
padding:20px;
background:#efefef;
border:2px solid #2e2e2e;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="form">
<?php
$user = $_POST[$user];
print $user ;
$host = $_POST['host']; // <-- inserisci qui l'indirizo ip di MySql
$user = $_POST['user']; // <-- nome utente del database
$pass = $_POST['pass']; // <-- password dell'utente
$db = $_POST['db']; // il database desiderato
$table = $_POST['table']; // la tabella da esportare in .csv
$file = $table; // il nome del file csv da generare
$link = mysql_connect($host, $user, $pass) or die("Can not connect." .
mysql_error());
/* usa i dati forniti per connetterti a MySql, se impossibile interrompi */
mysql_select_db($db) or die("Can not connect.");
// seleziona il db desiderato oppure interrompi
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("d-m-Y_H-i",time());
// il nome del file sara' composto da quello scelto all'inizio e la data ed ora oggi
/* setta le specifiche del file csv */
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output; // il file e' pronto e puo' essere scaricato
exit;
?>
</div>
</div>
</body>
</html>`
However this doesn't give me the first part the form for users to enter this information. Plus I would like to be able to run this only one time and get multiple files downloaded. for instance if I have three tables
table 1
table 2
table 3
It would download table1.csv, table2.csv, and table3.csv all in in their own csv files no concatenating or appending them together.
Right now I'm having trouble getting a test login form to run properly:
login.php
<html>
<body>
<form name="myform" action="secondpage.php" method="post">
<div>Username: <input type="text" name="username" value="" /></div>
<div>Password: <input type="password" name="password" value="" /></div>
<div> <input type="submit" /> </div>
</form>
</body>
</html>
secondpage.php
<html>
<body>
Welcome <?php echo $_POST["username"]; ?>!<br />
Your password is: <?php echo $_POST["password"]; ?>
</body>
</html>
Nothing comes up in in the secondpage.php after I click submit query for login.php
The Form should be able to fill out these fields below, however $host and $db could probably remain the same so might not need form entry for these... just need to set the values.
$host = $_POST['host']; // <-- inserisci qui l'indirizo ip di MySql
$user = $_POST['user']; // <-- nome utente del database
$pass = $_POST['pass']; // <-- password dell'utente
$db = $_POST['db']; // il database desiderato
$table = $_POST['table']; // la tabella da esportare in .csv
$file = $table; // il nome del file csv da generare
Any help you could give me some help it would be great.