如何将数据插入到实时创建的表中 [英] How do I can insert data into a table created in real time

查看:61
本文介绍了如何将数据插入到实时创建的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我对插入的东西有疑问,我创建了一种构建动态表的方法,但是如果表是实时创建的,我就无法插入行而不去源并使用Insert into'real_time_table' 。

是否存在插入数据的任何方式而没有指定表和字段名称插入的位置? (导致它是一个实时表)。



我尝试过:



创建实时时间表的代码(工作):



Hey, im having a doubt about an insert thing, i have created a way to build dynamic tables but if the table is created in real time i cant insert rows without go to the source and use "Insert into 'real_time_table'".
Does exist any way of insert data without specifying the table and the field names where to insert? (cause its a real time table).

What I have tried:

Code to create a real time table (Working):

<html><head><title>Inserir novas tabelas dinamicamente</title></head>
<body>
<html>
<head>
<style>

</style>
</head>
<body>

<ul>
  <li><a href="welcome.php">Home</a></li>
  <li><a href="">Info</a></li>
  <li><a href="">Info</a></li>
  <li><a href="welcome.php">Voltar</a></li>

</ul>
</body>
</html>
<br>
<br>
<?php	
$self = $_SERVER['PHP_SELF'];
$fields = null;
$db = null;

if(isset($_POST['field_submit'])) {
  $fields = $_POST['fields'];
}
else if(isset($_POST['db_submit'])) {
  $db =     $_POST['db'];
  $name =   $_POST['name'];
  $table =  $_POST['table'];
  $type =   $_POST['type'];
  $size =   $_POST['size'];
}

if( !$fields and !$db )
{
  $form ="<form action=\"$self\" method=\"post\">";
  $form.="Quantos fields deseja na sua nova tabela?<br>";
  $form.="<input type=\"text\" name=\"fields\" size=\"5\">";
  $form.="<input type=\"submit\" name=\"field_submit\" value=\"Submeter\">";
  echo($form);
}
else if( !$db )
{ 
  $form ="<form action=\"$self\" method=\"post\">";
  $form.="Escreve a Base de dados onde deseja criar:     <input type=\"text\" name=\"db\"><br>";
  $form.="Nome tbl:  <input type=\"text\" name=\"table\" size=\"\"><br> ";
  for ($i = 0 ; $i <$fields; $i++) 
  {
	  
    $form.="<br>Nome de Coluna:<input type=\"text\" name=\"name[$i]\" size=\"50\"><br>";
    $form.="<br>Tipo de dados: <select name=\"type[$i]\">";
    $form.="<option value=\"char\">Letras</option>";	
    $form.="<option value=\"varchar\">Letras e simbolos</option>";
    $form.="<option value=\"int\">Numero sem Virgula</option>";
    $form.="<option value=\"float\">Numeros com casa decimais</option>";
    $form.="</select> ";
    $form.="Size:<input type=\"text\" name=\"size[$i]\" size=\"5\"><br>";
  }
  $form.=" <br><input type=\"submit\" name=\"db_submit\" value=\"Submit\"></form>";
  echo($form);
}
else
{
  $conn = mysqli_connect("127.0.0.1", "root", "", "")
	or die("Could not connect.");

  $rs = mysqli_select_db($conn, $db)
	or die("Could not select database.");
	
  $num_columns = count($name);

  $sql = "create table $table (";
  for ($i = 0; $i < $num_columns; $i++) 
  {
    $sql .= "$name[$i] $type[$i]";
    if(($type[$i] =="char") or ($type[$i] =="varchar"))
    {
      if($size[$i] !="" ){ $sql.= "($size[$i])"; }
    }
    if(($i+1) != $num_columns){ $sql.=","; }
  }
  $sql .= ")";

 

  $result = mysqli_query($conn, $sql)
	or die("Could not execute SQL query");

  if ($result) {     
	echo("RESULT: table \"$table\" has been created");
  }
}
?>
<?php
// Inicia a sessao
session_start();
 
//vê se o user está on senão redireciona para a página de login
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
    header("location: login.php");
    exit;
}
?>
</body></html>

推荐答案

self =


_SERVER ['PHP_SELF'];
_SERVER['PHP_SELF'];


fields = null;
fields = null;


这篇关于如何将数据插入到实时创建的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆