Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "172.16.172.30";
- $username = "qUser";
- $password = "12345";
- $dbname = "test";
- $data = $_POST['date'];
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $explodedDataByNewLine = explode("\n", $data);
- $fExploded = explode("\t",$explodedDataByNewLine[0]);
- $sql = "CREATE TABLE temporary (temp VARCHAR(255))"; // loop through column creation
- $sql3 = "SELECT * FROM temporary";
- $i = 0;
- if ($conn->query($sql) === TRUE)
- {
- $i4r = 0;
- echo "Table created<br>";
- foreach ($fExploded as $tab)
- {
- $fExploded = explode("\t",$explodedDataByNewLine[$i4r]);
- // for every new line, divide the value of the line by tabs, so, value[0] will be the 1st from the row, value[1] the 2nd...
- $newExploded .= $fExploded[$i];
- if ($conn->query("ALTER TABLE temporary ADD (temp".$i." VARCHAR(255))") === TRUE)
- {
- foreach ($explodedDataByNewLine as $value)
- {
- if ($conn->query("INSERT INTO temporary (temp".$i.") VALUES ('$value')") === TRUE)
- {
- }
- else
- {
- echo $conn->error . "<br>";
- }
- }
- echo $newExploded;
- }
- else
- {
- echo $conn->error . "<br>";
- }
- ++$i;
- }
- ++$i4r;
- }
- else
- {
- echo "Table already exists<br>";
- foreach ($fExploded as $tab)
- {
- if ($conn->query("ALTER TABLE temporary ADD (temp".$i." VARCHAR(255))") === TRUE)
- {
- foreach ($explodedDataByNewLine as $value)
- {
- $newValue = explode("\t",$value);
- // for every new line, divide the value of the line by tabs, so, value[0] will be the 1st from the row, value[1] the 2nd...
- foreach ($newValue as $xyValue)
- {
- if ($conn->query("INSERT INTO temporary (temp".$i.") VALUES ('$xyValue')") === TRUE)
- {
- }
- else
- {
- echo $conn->error . "<br>";
- }
- }
- }
- }
- else
- {
- echo $conn->error . "<br>";
- }
- ++$i;
- }
- }
- // if ($conn->query($sqlColumn) === TRUE)
- // {
- // echo "column added";
- // }
- // else
- // {
- // echo $conn->error;
- // }
- $result = mysqli_query($conn,$sql3)
- or die("Error: ".mysqli_error($conn));
- echo "<table border='1'>\n";
- $ncols = mysqli_field_count($conn);
- while ($fieldinfo=mysqli_fetch_field($result))
- {
- $column_name = $fieldinfo->name;
- }
- echo "<td>$column_name</td>\n"; // loop 4 column name
- while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
- {
- echo "<tr>\n";
- foreach ($row as $item)
- {
- echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
- }
- echo "</tr>\n";
- }
- echo "</table>\n";
- mysqli_free_result($result);
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement