PHP中的Select语句

PHP中的Select语句,php,mysql,Php,Mysql,我不知道那是什么错误 您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第1行“Resource id 3”附近使用的正确语法 需要帮忙吗 <?php //Connecting to sql db. if(!($database=mysql_connect("localhost", "root", "") )) die(mysql_error()); if(!mysql_select_db("Ehab",$database) ) die(mysql_

我不知道那是什么错误

您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第1行“Resource id 3”附近使用的正确语法

需要帮忙吗

<?php
//Connecting to sql db.

if(!($database=mysql_connect("localhost", "root", "") ))

    die(mysql_error()); 

if(!mysql_select_db("Ehab",$database) )
    die(mysql_error()); 

//Sending form data to sql db.
if(isset($_POST["websites"]))
    //html klma
    $sitesphp=$_POST["websites"];

if(isset($_POST["description"]))
    $descriptionphp=$_POST["description"];

$query= "INSERT INTO website (sites, des) VALUES ('$sitesphp','$descriptionphp')";

//take query and then put it down 
//in result

if(!($result=mysql_query($query,$database)))
    {
        print("etla3 bara ya homar");
        die(mysql_error()); 
    }?>
<html>
<head>
<meta charset="utf-8">
    <title>Database Update</title>
    </head>
    <body>
    <h1>Database successfully updated.</h1>
    <table>
    <tr>
    <th>URL</th><th>description</th>
    </tr>
    <?php
    //error occurs here
    if ( !( $result = mysql_query( "SELECT sites,des FROM website", $database ) ) )
        {
            print( "<p>Could not execute query!</p>" );
            die( mysql_error() );
        }

mysql_close( $database );

while ( $row = mysql_fetch_row( $result ) )
    print( "<tr><td>" . $row[ 0 ] . "</td><td>" . $row[ 1 ] . "</td></tr>" );
?>
</table>
</body>
</html>
我不会把这个

 mysql_fetch_row()
之后

因为我猜在关闭连接后结果是空的。也许这也是丢失资源的来源,因为它已经关闭


顺便说一句,据我记忆所及,错误来自SQL而不是php,因此第1行不是php文件的第1行,而是SQL语句的第1行。

此代码中没有错误。它可能在代码的其他部分。您的数据库是什么样子的?旁注:您对sql注入非常开放。如果错误确实存在于该文件中,则是您的insert查询导致了问题,应该是您尝试插入的值的某些内容,它将返回到侧注:@user3597606 Put error_reportingE_ALL;和ini设置“显示错误”,1;在文件的开头显示错误。打印变量$siteshp和$descriptionphp,并确保它们返回的是您期望的值。+1以防万一,尽管这是一个SQL错误是的,我同意这是一个SQL错误。刚才我的回答是:-
  mysql_close()