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
11 Respostas
+ 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));
+ 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.
+ 7
In that case you have to share your code for proper answer. You can copy the code in codeplayground and link it here.
+ 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
+ 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;
0
i check that and that is good
0
here it is post.php and profile.php
0
where i need to include that to post.php?
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
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;