0

SQL QUERY

$sql = "  INSERT INTO foldertable(`serverToken` , `folderName` , `folderid` , `folderPath` , `createdTime` , `LastEdited` , `previewPath` , `userFolderPathName`)
                     SELECT (SELECT serverToken FROM `servertoken` WHERE `userToken` = ? LIMIT 1) ,? ,? ,? ,CURRENT_TIMESTAMP() ,CURRENT_TIMESTAMP() ,? ,?
                     FROM foldertable
                     WHERE (`folderPath` = ?
                     AND serverToken = (SELECT serverToken FROM `servertoken` WHERE `userToken` = ? LIMIT 1))

The $sql is working fine. but the problem is in mysqli_stmt_execute returning true when folderPath is not matched but returning false when userToken not found in servertoken database.

I am unable to understand this behavior. I will be grateful if you can explain this.

I think given info is enough to debug this, if not tell me.

Martin
  • 22,212
  • 11
  • 70
  • 132
S B RAKESH RATH
  • 443
  • 3
  • 10
  • If `userToken` is not found, the insert query will fail. Your columns might not be supporting NULL values – nice_dev Apr 23 '21 at 15:58
  • You could add `servertoken` table as inner join so you dont need the second where statement – Baracuda078 Apr 23 '21 at 15:58
  • You can also cache `SELECT serverToken FROM servertoken WHERE userToken = ? LIMIT 1` in a variable in the query. – nice_dev Apr 23 '21 at 15:59
  • Please share more details. What's the exact question? Why `mysqli_stmt_execute` returns either `true` or `false`? – Nico Haase Apr 23 '21 at 16:01
  • Suggest reformulating the query to have the `( SELECT serverToken ... ) as a 'derived' table, thereby needing to state it only once. – Rick James Apr 23 '21 at 20:14

0 Answers0