Jump to content

Archived

This topic is now archived and is closed to further replies.

skallsen

mysql_field_count()

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!

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.