Jump to content

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/10747-mysql_field_count/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/10747-mysql_field_count/#findComment-40168
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/10747-mysql_field_count/#findComment-40180
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.