By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,274 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,274 IT Pros & Developers. It's quick & easy.

how to find if the query was successful

P: 11
I have a insert query which is fired when the form is submitted sometimes users enters illegal characters or for some reason query is not executed properly
how to find if the query has run successfully or not
Dec 10 '09 #1
Share this Question
Share on Google+
3 Replies

code green
Expert 100+
P: 1,726
Very bad practice. Always cleanse form data BEFORE inserting into a database.
By cleanse I mean protect from SQL injection and validate the data.
As for checking if queries work, php query execution functions do return error codes.
And there are rows affected functions.
I cannot be more helpful because you omitted your DB engine
Dec 10 '09 #2

P: 5
It's true, you should ensure that the data is correct before launch the query, otherwise you can have even security problems on your Database system.

Anyway you can check a response:

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT....",$db);
  2. if ($result===false)
  3. {
  4.  echo "error!"
  5. } else {
  6.  //actions....
  7. }

-------------------------------------, diseño web
Dec 15 '09 #3

Expert 100+
P: 1,044
~carmarri, the OP stated that they were using an INSERT query. INSERT and UPDATE queries do not create result resources, as they have no results.
Dec 15 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.