4

I am inserting the values using PDO but i am getting error as:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'desc,price,nick_name,gender,size,color,birth_date,uname,uphone,ucountry,ustate,u' at line 1' in C:\wamp\www\aa\abc.php:58 Stack trace: #0 C:\wamp\www\www\aa\abc.phpphp(58): PDOStatement->execute(Array) #1 {main} thrown in C:\wamp\www\www\aa\abc.php.php on line 58

also getting Warning: implode() [function.implode]: Bad arguments for implode function

Code:

foreach ($_POST['pcheck'] as $p_check) ////storing checkbox values
{
    $pcheckp[] = $p_check;
}   $finalcheck = implode(',', $pcheck);
foreach ($_POST['pinc'] as $p_inc) ////storing inputfield values
{
    $pinc[] = $p_inc;
}   $finalpinc = implode(',', $pinc);

$sql = "INSERT INTO list (u_id,list_type,list_ff,breed,title,desc,price,nick_name,gender,size,color,birth_date,uname,uphone,ucountry,ustate,ucity,usite,pcheck,pinc,photo)
VALUES(:uid,:list_type,:list_ff,:breed,:title,:desc,:price,:nick_name,:gender,:size,:color,:date,:uname,:uphone,:ucountry,:ustate,:ucity,:usite,:pcheck,:pinc,:p_photo)";
$q = $db->prepare($sql);
$q->execute(array(':uid'=>dd,
                ':list_type'=>$list_type,
                ':breed'=>$breed,
                ':title'=>$title,
                ':desc'=>$desc,
                ':price'=>$price,
                ':list_ff'=>$list_ff,
                ':nick_name'=>$nick_name,
                ':gender'=>$gender,
                ':size'=>$size,
                ':color'=>$color,
                ':date'=>$date,
                ':uname'=>$uname,
                ':uphone'=>$uphone,
                ':ucountry'=>$ucountry,
                ':ustate'=>$ustate,
                ':ucity'=>$ucity,
                ':usite'=>$usite,
                ':pcheck'=>$finalcheck,
                ':pinc'=>$finalpinc,
                ':p_photo'=>$p_photo));

$_POST['pcheck'] and $_POST['pinc'] is used to get checkbox and input values which i am going to store in column in mysql.

I have checked many times to find the syntax error in insert query but nothing wrong is in it

Hoping to get help Thanks!

Gopal
  • 861
  • 12
  • 18
  • desc is a reserved word in mysql use \`desc\` or change the column name – Jesper Blaase Nov 15 '13 at 13:20
  • @JesperBunnyJensen thanks much..but i have a doubt that as **desc** is reserved word then why it didnt shown any error in mysql – Gopal Nov 15 '13 at 13:26
  • @user2996371 - It did show you an error in Mysql; it's right there at the top of your question. If you mean that you didn't get an error in PHPMyAdmin, that's because it processes the SQL you enter before running it - columns and tables are wrapped in backticks for you. – andrewsi Nov 15 '13 at 13:47
  • yes..in PHPMyAdmin..ok thanks for your help :) – Gopal Nov 15 '13 at 13:51

1 Answers1

2

for Warning: implode()

$finalcheck = implode(',', $pcheck);

should be

$finalcheck = implode(',', $pcheckp);

also desc is reserved for mysql you need to use it with `

    $sql = "INSERT INTO list (`u_id`,`list_type`,`list_ff`,`breed`,`title`,`desc`,`price`,`nick_name`,`gender`,`size`,`color`,`birth_date`,`uname`,`uphone`,`ucountry`,`ustate`,`ucity`,`usite`,`pcheck`,`pinc`,`photo`)
VALUES(:uid,:list_type,:list_ff,:breed,:title,:desc,:price,:nick_name,:gender,:size,:color,:date,:uname,:uphone,:ucountry,:ustate,:ucity,:usite,:pcheck,:pinc,:p_photo)";
Harish Singh
  • 3,359
  • 5
  • 24
  • 39