0

这是我的代码是否有任何语法错误,请指导我

$degree = $_POST['edu'];

$board  = $_POST['bu'];

$result = $_POST['rdd'];

$marks  = $_POST['tm'];

$maketemp = "CREATE TEMPORARY TABLE temp_table_1 ( `degree` varchar(100),`board` varchar(100),`resultd` varchar(100), `marks` varchar(100),)";

mysql_query($maketemp);

$insertemp = "INSERT INTO temp_table_1 (degree, board, resultd, marks ) VALUES ('$degree', '$board', '$resultd', '$marks',) ";

mysql_query($insertemp);

$show =  mysql_query("SELECT * FROM temp_table_1");


if($show)
{
    while($row = mysql_fetch_assoc($show)){

        echo $row['degree'];
    }
4

3 回答 3

1

您的两个查询中的语法错误,只需将您的两个查询替换为...

$maketemp = "CREATE TEMPORARY TABLE temp_table_1 ( `degree` varchar(100),`board` 
varchar(100),`resultd` varchar(100), `marks` varchar(100))";  // removed last comma

  mysql_query($maketemp);

$insertemp = "INSERT INTO temp_table_1 (degree, board, resultd, marks ) VALUES ('$degree', 
'$board', '$resultd', '$marks') ";  // removed last comma
于 2013-03-27T04:15:02.027 回答
0

查询中有一些错误。从 create table 中的查询末尾删除 TEMPORARY 和 ','。

改成这个

CREATE TABLE temp_table_1 ( `degree` varchar(100),`board` varchar(100),`resultd` varchar(100), `marks` varchar(100))

INSERT INTO temp_table_1 (degree, board, resultd, marks ) VALUES ('".$degree."','".$board."','".$resultd."', "'.$marks."'")
于 2013-03-27T04:27:38.310 回答
0

我发现 4 个错误:

Extra comma after`marks` varchar(100)
Extra comma after '$marks'
Missing 'd' on $result = $_POST['rdd'];
Missing end brace of the if statement

下面是一个工作版本。我建议使用

    die( die(mysql_error() . "<br>Query: " . ...) 

在每个 mysql_query() 之后。它提供了很多帮助。

$degree = $_POST['edu'];
$board = $_POST['bu'];
$resultd = $_POST['rdd'];
$marks = $_POST['tm'];

$maketemp = "CREATE TEMPORARY TABLE temp_table_1 ( 
    `degree` varchar(100),
    `board` varchar(100),
    `resultd` varchar(100), 
    `marks` varchar(100)
)";

mysql_query($maketemp) or die(mysql_error() . "<br>Query: " . $maketemp);

$insertemp = "INSERT INTO temp_table_1 (
    degree, board, resultd, marks 
    ) VALUES (
    '$degree', '$board', '$resultd', '$marks'
) ";

mysql_query($insertemp) or die(mysql_error() . "<br>Query: " . $inserttemp);

$select_temp = "SELECT * FROM temp_table_1";
$show = mysql_query($select_temp)  or die(mysql_error() . "<br>Query: " . $select_temp);

if($show) { 

    while($row = mysql_fetch_assoc($show)){
      echo "<br>".$row['degree'];
      echo "<br>".$row['board'];
      echo "<br>".$row['resultd'];
      echo "<br>".$row['marks'];
    }

}
?>
于 2013-03-27T05:03:10.603 回答