bilis_money Posted August 10, 2006 Share Posted August 10, 2006 Yo! brothers...i have codes here,[code]//insert new record now$query = "INSERT INTO topics (title, description, url) VALUES ('$title_tmp', '$descrip_tmp', '$url_tmp'";mysql_query($query) or die('Error, insert query failed');$COerr_msgs->err_msgs('add1'); [/code]I would like to add conditional statement with the MySQL query,let say if the insertion of the new record into the database is successful,then i want to add a successful message that it was successfully added.Now how could i determine if the new record was successfully inserted?I guess i have already known this before but maybe i have merely forgotten so.thank you very much in advance. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted August 10, 2006 Share Posted August 10, 2006 if(mysql_query($query)){ echo "success. it worked. good job."; }else{ echo "it failed because: ".mysql_error(); } Quote Link to comment Share on other sites More sharing options...
bilis_money Posted August 10, 2006 Author Share Posted August 10, 2006 thanks miccah Quote Link to comment Share on other sites More sharing options...
Silverado_NL Posted August 10, 2006 Share Posted August 10, 2006 after you insterted the data into the database, you could query and fetch it again.and if one of the array field is empty you could determin if it went ok or not!i think something like this would do it.just fill in the conditional statement with what you want and thats it![CODE]$query ="SELECT * FROM topics WHERE title = $title_tmp";$data = mysql_query($query);$fetch = mysql_fetch_array($data);if ( (empty($fetch['title'])) || (empty($fetch['description'])) || (empty($fetch['url'])) ){}[/CODE] Quote Link to comment Share on other sites More sharing options...
mainewoods Posted August 10, 2006 Share Posted August 10, 2006 Use [code]mysql_affected_rows ( );[/code]http://www.php.net/manual/en/function.mysql-affected-rows.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.