简体   繁体   中英

MYSQL error while inserting data using php

I am practicing php and sql. at a stage when I'm trying to enter a record into a table with 2 exiting records. but it doesn't add and show an error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=('Aqeela','Nasreen','Hakeem Chattah')' at line 1"

Why is it not entering a record in data base. Is there any syntax error?

$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());
    }

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')"

I think there is an error in your INSERT INTO statment, you have written wrong VALUES part.

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

you need to remove "=" from your VALUES= part like this.

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

please correct this line of code in your code and check it again.

VALUES=(...)删除=符号

VALUES后面没有'=',只是:VALUES(val1,val2,..,valN)

向我查询sy值k bad = ka号删除kr做。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM