i got some error with mysql help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

i got some error with mysql help?

Fatal error: Uncaught PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 in C:\xampp\htdocs\website.com\classes\DB.php:12 Stack trace: #0 C:\xampp\htdocs\website.com\classes\DB.php(12): PDOStatement->execute(Array) #1 C:\xampp\htdocs\website.com\classes\Post.php(13): DB::query('INSERT INTO pos...', Array) #2 C:\xampp\htdocs\website.com\profile.php(54): Post::createPost('sadasdasd', '1', '1') #3 {main} thrown in C:\xampp\htdocs\website.com.com\classes\DB.php on line 12

6th Aug 2019, 1:00 PM
Luka Blagojevic
Luka Blagojevic - avatar
11 Answers
+ 8
Luka Blagojevic this query of insert statement is causing the error. You are parsing the postbody with escaping symbol and quotes doesn't going to get the body content or image or topics. You need to define variable to store and retrieve image information. You can compare the id values and fetch any profile id details manually by their id. You can use self to get the data store in the $postbody $postImg = ""; $topics = self::getTopics($postbody); if ($loggedInUserId == $profileUserId) { DB::query('INSERT INTO posts VALUES (:id, :postbody, NOW(), :userid, 0, :postimg, :topics)', array(':id'=>0,':postbody'=>$postbody, ':userid'=>$profileUserId, ':postimg'=>$postImg,':topics'=>$topics)); you can also try by starting post body with null that will help in tracing the value like this way DB::query('INSERT INTO posts VALUES (null, :postbody, NOW(), :userid, 0, :postimg, :topics)', array(':id'=>0,':postbody'=>$postbody, ':userid'=>$profileUserId, ':postimg'=>$postImg,':topics'=>$topics));
6th Aug 2019, 5:30 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
Luka Blagojevic 1136 Column doesn't match value occurs in general when you have any syntax error in the insert statement or you forget to put separator (,) between multiple values in values() just check your syntax again. And if possible include the query in the question which you are using to fetch data with php and MySQL for getting more help.
6th Aug 2019, 1:29 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
In that case you have to share your code for proper answer. You can copy the code in codeplayground and link it here.
6th Aug 2019, 1:37 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
Luka Blagojevic you can add this in post.php as there you have used the if condition to equate login ID to user ID so further execution you have to use the :id and you can try by starting from null in case it execute https://code.sololearn.com/Wmqid1hlMcAm/?ref=app you can even try this stack overflow solution you just need to change your code in some lines https://stackoverflow.com/questions/43463366/fatal-error-uncaught-pdoexception-sqlstatehy093-invalid-parameter-number-n/43464179#43464179
6th Aug 2019, 6:04 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
Luka Blagojevic try to access this too by the id or null to get images. You can try to define $images=""; for getting some execution. // $images=""; if ($loggedInUserId == $profileUserId) { DB::query('INSERT INTO posts VALUES (:id, :postbody, NOW(), :userid, 0, \'\')', array(':postbody'=>$postbody, ':userid'=>$profileUserId)); $postid = DB::query('SELECT id FROM posts WHERE user_id=:userid ORDER BY ID DESC LIMIT 1;', array(':userid'=>$loggedInUserId))[0]['id']; return $postid;
6th Aug 2019, 6:12 PM
GAWEN STEASY
GAWEN STEASY - avatar
0
i check that and that is good
6th Aug 2019, 1:31 PM
Luka Blagojevic
Luka Blagojevic - avatar
6th Aug 2019, 4:27 PM
Luka Blagojevic
Luka Blagojevic - avatar
0
here it is post.php and profile.php
6th Aug 2019, 4:27 PM
Luka Blagojevic
Luka Blagojevic - avatar
0
where i need to include that to post.php?
6th Aug 2019, 5:52 PM
Luka Blagojevic
Luka Blagojevic - avatar
0
oh awesome post work but now img dont wanna display i got this when i try: Fatal error: Uncaught PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 in C:\xampp\htdocs\website.com\classes\DB.php:12 Stack trace: #0 C:\xampp\htdocs\website.com\classes\DB.php(12): PDOStatement->execute(Array) #1 C:\xampp\htdocs\website.com\classes\Post.php(29): DB::query('INSERT INTO pos...', Array) #2 C:\xampp\htdocs\website.com\profile.php(55): Post::createImgPost('', '1', '1') #3 {main} thrown in C:\xampp\htdocs\website.com\classes\DB.php on line 12
6th Aug 2019, 6:05 PM
Luka Blagojevic
Luka Blagojevic - avatar
0
this is on line 29 if ($loggedInUserId == $profileUserId) { DB::query('INSERT INTO posts VALUES (\'\', :postbody, NOW(), :userid, 0, \'\')', array(':postbody'=>$postbody, ':userid'=>$profileUserId)); $postid = DB::query('SELECT id FROM posts WHERE user_id=:userid ORDER BY ID DESC LIMIT 1;', array(':userid'=>$loggedInUserId))[0]['id']; return $postid;
6th Aug 2019, 6:06 PM
Luka Blagojevic
Luka Blagojevic - avatar