Advertisement
Guest User

php prob

a guest
Mar 3rd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.73 KB | None | 0 0
  1. <?php
  2. $servername = "172.16.172.30";
  3. $username = "qUser";
  4. $password = "12345";
  5. $dbname = "test";
  6. $data = $_POST['date'];
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. // Check connection
  10. if ($conn->connect_error) {
  11.     die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. $explodedDataByNewLine = explode("\n", $data);
  15. $fExploded = explode("\t",$explodedDataByNewLine[0]);
  16.  
  17. $sql = "CREATE TABLE temporary (temp VARCHAR(255))"; // loop through column creation
  18. $sql3 = "SELECT * FROM temporary";
  19. $i = 0;
  20. if ($conn->query($sql) === TRUE)
  21. {
  22.     $i4r = 0;
  23.     echo "Table created<br>";
  24.     foreach ($fExploded as $tab)
  25.     {
  26.         $fExploded = explode("\t",$explodedDataByNewLine[$i4r]);
  27.         // 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...
  28.         $newExploded .= $fExploded[$i];
  29.         if ($conn->query("ALTER TABLE temporary ADD (temp".$i." VARCHAR(255))") === TRUE)
  30.         {
  31.            
  32.             foreach ($explodedDataByNewLine as $value)
  33.             {
  34.                
  35.                     if ($conn->query("INSERT INTO temporary (temp".$i.") VALUES ('$value')") === TRUE)
  36.                     {
  37.                     }
  38.                     else
  39.                     {
  40.                         echo $conn->error . "<br>";
  41.                     }
  42.                    
  43.             }
  44.             echo $newExploded;
  45.         }
  46.         else
  47.         {
  48.             echo $conn->error . "<br>";
  49.         }
  50.         ++$i;
  51.     }
  52.     ++$i4r;
  53. }
  54. else
  55. {
  56.     echo "Table already exists<br>";
  57.     foreach ($fExploded as $tab)
  58.     {
  59.        
  60.         if ($conn->query("ALTER TABLE temporary ADD (temp".$i." VARCHAR(255))") === TRUE)
  61.         {
  62.             foreach ($explodedDataByNewLine as $value)
  63.             {
  64.                 $newValue = explode("\t",$value);
  65.                 // 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...
  66.                 foreach ($newValue as $xyValue)
  67.                 {
  68.                     if ($conn->query("INSERT INTO temporary (temp".$i.") VALUES ('$xyValue')") === TRUE)
  69.                     {
  70.                     }
  71.                     else
  72.                     {
  73.                         echo $conn->error . "<br>";
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.         else
  79.         {
  80.             echo $conn->error . "<br>";
  81.         }
  82.         ++$i;
  83.     }
  84. }
  85. // if ($conn->query($sqlColumn) === TRUE)
  86. // {
  87.     // echo "column added";
  88. // }
  89. // else
  90. // {
  91.     // echo $conn->error;
  92. // }
  93. $result = mysqli_query($conn,$sql3)
  94. or die("Error: ".mysqli_error($conn));
  95.  
  96.        
  97.         echo "<table border='1'>\n";
  98.         $ncols = mysqli_field_count($conn);
  99.         while ($fieldinfo=mysqli_fetch_field($result))
  100.         {
  101.             $column_name  = $fieldinfo->name;
  102.         }
  103.         echo "<td>$column_name</td>\n"; // loop 4 column name
  104.         while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
  105.         {
  106.            
  107.             echo "<tr>\n";
  108.             foreach ($row as $item)
  109.             {
  110.                 echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
  111.             }
  112.             echo "</tr>\n";
  113.         }
  114. echo "</table>\n";
  115.    
  116. mysqli_free_result($result);
  117. $conn->close();
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement