Skip to content
Advertisement

Else element not returning the correct result

I have created a select statement using php to return results to an HTML based on user input. The feedback is returned based on the input fields matching fields in a manually populated table. The select statement should return the highest ID. The form inserts data into the ‘adoption’ table. The results then return a row from the ‘dogs’ table based on the fields below matching in the ‘adoption’ table.

JavaScript

The results are then displayed in a table in the HTML section of the page.

JavaScript

However, if I input data to the ‘adoption’ table that doesn’t match any of the rows in the ‘dogs’ table it will return the row that was last matched instead of the statement in the else. Does anyone have any advice on how to fix this?

JavaScript

SQL query result

Advertisement

Answer

Looking at the SQL code it will return the last ID that matched not the last ID. You can select only the last insert with the following,

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement