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!

4
  • desc is a reserved word in mysql use `desc` or change the column name Commented Nov 15, 2013 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 Commented Nov 15, 2013 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. Commented Nov 15, 2013 at 13:47
  • yes..in PHPMyAdmin..ok thanks for your help :) Commented Nov 15, 2013 at 13:51

1 Answer 1

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)";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.