-2

我正在练习php和sql。在我尝试将记录输入到具有 2 个现有记录的表中的阶段。但它不会添加并显示错误

“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '=('Aqeela','Nasreen','Hakeem Chattah')' 附近使用正确的语法”

为什么它没有在数据库中输入记录。有语法错误吗?

$username="root";
$pass="";
$database="addressbook";
$server="127.0.0.1";

$con=mysql_connect($server,$username,$pass);
$db_found=mysql_select_db($database,$con);
if($db_found)
{
$sql_insert="INSERT INTO table_address_book(f_name,l_name,address) VALUES=('Aqeela','Nasreen','Hakeem Chattah')";
    $result=mysql_query($sql_insert);
    if(!$result){
        print "sorry cannot proceed your request<br>".mysql_error();

        }
else
{
//  print "recorded entered successfuly<br>";
//  print "now dATABASES AFTER EDITING ARE<BR><br>";
    $new_sql="SELECT*FROM table_address_book";
    $result_after_editing=mysql_query($new_sql);
    while($db_field_edited=mysql_fetch_assoc($result_after_editing))
    {
        print $db_field_edited['ID']."<br>";
        print $db_field_edited['f_name']."<br>";
        print $db_field_edited['l_name']."<br>";
        print $db_field_edited['address']."<br>";
        print "<BR><BR><BR>";


        }
        mysql_close($con);
    }
}
else
{
    die("unable to connect database ".mysql_error());
    }
4

4 回答 4

4

The error clearly shows place where error in syntax occur.

Remove that =

INSERT INTO table_address_book(f_name,l_name,address) VALUES('Aqeela','Nasreen','Hakeem Chattah')"
于 2013-07-17T12:55:44.067 回答
1

我认为您的 INSERT INTO 语句中有错误,您写错了 VALUES 部分。

$sql_insert="INSERT INTO table_address_book(f_name,l_name,address) VALUES=('Aqeela','Nasreen','Hakeem Chattah')";

您需要像这样从您的 VALUES= 部分中删除“=”。

$sql_insert="INSERT INTO table_address_book(f_name,l_name,address) VALUES('Aqeela','Nasreen','Hakeem Chattah')";

请更正代码中的这行代码并再次检查。

于 2013-07-17T13:00:09.143 回答
0

Remove the = sign from VALUES=(...)

于 2013-07-17T12:56:39.850 回答
0

VALUES 之后没有“=”,只有:VALUES (val1, val2, .., valN)

于 2013-07-17T12:56:46.510 回答