Best unofficial Apache Server developers community |
|
I have this code:
how can i check if $local_id does not exist in the db and display an error?
posted via StackOverflow
|
![]()  
|
|
|
 
|
You can use the following query:
This query will return one number: how many records have matched your query. If this is zero, you surely know that there are no records with this ID. This is more optimal than other solutions posted in case you only want to check for the existence of the ID, and don't need the data (if you use Be sure to ALWAYS escape data that came from the outside (this time GET) before you put it into a query ( If you fail to do so, you are a possible victim for SQL Injection. |
|
 
|
|
|
 
|
You could have a $count variable and increment it in the while loop. After the loop, check the count, if it is 0, then echo an error message. |