Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在mysql中如何将排列结果插入到表中_Php_Mysql_Sql - Fatal编程技术网

Php 在mysql中如何将排列结果插入到表中

Php 在mysql中如何将排列结果插入到表中,php,mysql,sql,Php,Mysql,Sql,我想将排列结果存储到mysql中的一个临时表中,以便在搜索脚本中使用它 <?php function permute($str,$i,$n) { if ($i == $n) { echo "$str\n"; echo "<br/>"; $query = mysql_query("CREATE TABLE temp( id int NOT NULL AUTO_INCREMENT,

我想将排列结果存储到mysql中的一个临时表中,以便在搜索脚本中使用它

<?php
function permute($str,$i,$n) {
    if ($i == $n) {
        echo "$str\n";
        echo "<br/>";

        $query = mysql_query("CREATE TABLE temp(
            id int NOT NULL AUTO_INCREMENT,
            number varchar(64) NOT NULL,
            PRIMARY KEY(id)
            )");

        $str = addslashes(trim($_POST['str']));

        $query = mysql_query("INSERT INTO temp (number) VALUES ('$str')")
            or die(mysql_error());
    }
    else {
        for ($j = $i; $j < $n; $j++) {
            swap($str,$i,$j);
            permute($str, $i+1, $n);
            swap($str,$i,$j); // backtrack.
        }
    }
}

// function to swap the char at pos $i and $j of $str.
function swap(&$str,$i,$j) {
    $temp = $str[$i];
    $str[$i] = $str[$j];
    $str[$j] = $temp;
}   

$str = @$_GET['number'] ;
permute($str,0,strlen($str)); // call the function.
  // Get the search variable from URL

?>

有人知道如何将置换结果插入到临时表中吗

我尝试插入到永久表中,但没有插入1234的24sets结果,只插入id 1-24。我认为问题是因为$str包含24组结果,但没有分开,因为它是一起打印出来的


有什么解决办法吗?

你真正的问题是
$str=addslashes(trim($\u POST['str']),在将其放入临时表之前,它正在尝试以post形式从web请求中检索值。
基本上,您是在用(可能没有设置)空白的内容过度编写变量。

哦,我希望在现实中你能安全地逃离你的输入参数,否则你的网站很快就会被接管。如果
number
曾经应该包含一个实际数字(1234),而不是某个字符串(ABC),则将其转换为数字数据(并返回到字符串)以彻底清理它(也应包括异常处理).

您知道如何在临时表中插入任何内容吗?在寻求解决方案之前,您至少应该尝试一下。那怎么办?我试图插入到一个永久表中,但它不起作用。。id已插入,但24组结果根本没有插入到表中。。。我添加$str=addslashes(trim($_POST['str']);$query=mysql\u query(“插入测试(数字)值('$str'))或die(mysql\u error());但只插入id,而不插入结果。。