skallsen Posted May 30, 2006 Share Posted May 30, 2006 Hey all, I'm so confused on how to use this: mysql_field_count()I'm not even sure it's what I should use in this case.I have this code to insert data into my db:$addestate = "INSERT INTO estate_sale_companies (estatename, estateaddress1, estateaddress2, estatecity, estatestate, estatezip, estatecounty, estatetelephone, estatewebsite, estateemail, estatecontact, contact_MNG, contact_KIC)VALUES ('$estatename, '$estateaddress1', '$estateaddress2', '$estatecity, '$estatestate', '$estatezip', '$estatecounty', '$estatetelephone', '$estatewebsite', '$estateemail', '$estatecontact', '$contact_MNG', '$contact_KIC')";$result = mysql_query($addestate);The insert isn't working and I want to check the result to see if it worked (if there is a result). How do I do that? I've read the MySQL manual on mysql_field_count() and I cannot figure out how to use it! Can someone give me the code to use to perform a check on this query?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10747-mysql_field_count/ Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 I wouldn't use mysqli_field_count() since it's PHP5 only (it's still not so widely used). There is an error with your query.Use this code:[code]$result = mysql_query($addestate) or die(mysql_error());[/code]Which will throw and error if one happens. You can use mysql_affected_rows() to check if a row was actually inserted as well:[a href=\"http://www.php.net/mysql_affected_rows\" target=\"_blank\"]http://www.php.net/mysql_affected_rows[/a]Also, there are is a problem with your code that I can see now:('$estatename, should be('$estatename', Yes, the smallest error can cause the entire script to fail. It's something that bothers me in programming. Quote Link to comment https://forums.phpfreaks.com/topic/10747-mysql_field_count/#findComment-40168 Share on other sites More sharing options...
skallsen Posted May 30, 2006 Author Share Posted May 30, 2006 Brilliant! Thank you, it's working great and now I can actually see where it was broken!Suzzy[!--quoteo(post=378302:date=May 29 2006, 11:52 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 29 2006, 11:52 PM) [snapback]378302[/snapback][/div][div class=\'quotemain\'][!--quotec--]I wouldn't use mysqli_field_count() since it's PHP5 only (it's still not so widely used). There is an error with your query.Use this code:[code]$result = mysql_query($addestate) or die(mysql_error());[/code]Which will throw and error if one happens. You can use mysql_affected_rows() to check if a row was actually inserted as well:[a href=\"http://www.php.net/mysql_affected_rows\" target=\"_blank\"]http://www.php.net/mysql_affected_rows[/a]Also, there are is a problem with your code that I can see now:('$estatename, should be('$estatename', Yes, the smallest error can cause the entire script to fail. It's something that bothers me in programming.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/10747-mysql_field_count/#findComment-40180 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.