A=1x3 means 1 row and 3 columns.
B=3x4 means 3 rows and 4 columns.
AB is a compatible multiplication because A has three columns and B has 3 rows.
However, BA is not a compatible multiplication because B has 4 columns while A has only 1 row.
The general trick is if you read the row/column of the two matrices as 1-3-3-4, and the two middle ones are identical, then AB would be a compatible multiplication. On the other hand, BA would read 3-4-1-3, since 4 and 1 are not identical, so it is not a valid multiplication.
Do remember 1x3 means 1 ROW and 3 COLUMNS.