Jump to content


Photo

mysql_field_count()


  • Please log in to reply
2 replies to this topic

#1 skallsen

skallsen
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 30 May 2006 - 02:37 AM

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!

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 04:52 AM

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:
$result = mysql_query($addestate) or die(mysql_error());
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.
~ D Kuang

#3 skallsen

skallsen
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 30 May 2006 - 05:14 AM

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) View Post[/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:
$result = mysql_query($addestate) or die(mysql_error());
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]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users